环境说明:
该系统第一次安装MysqL。
自己指定安装目录,指定数据文件目录。
linux系统版本: CentOS 7.3 64位
注:未防止混淆,这里都用绝对路径执行命令
步骤:
1、在根目录下创建文件夹software和数据库数据文件/data/MysqL
#mkdir /software/
#mkdir /data/MysqL
2、上传MysqL-5.7.21-linux-glibc2.12-x86_64.tar.gz文件到/software下
#cd /software/
#tar -zxvf MysqL-5.7.21-linux-glibc2.12-x86_64.tar.gz
#mv /software/MysqL-5.7.21-linux-glibc2.12-x86_64/ /software/MysqL
#groupadd MysqL
#chown -R MysqL:MysqL /software/MysqL/
#chown -R MysqL:MysqL /data/MysqL/
#chown -R MysqL /software/MysqL/
#chmod -R 755 /software/MysqL/
7、安装libaio依赖包,由于我买的腾讯云服务器centos系统自带的有这个依赖包所以不需要安装,不过自带的依赖包会报错,后面介绍解决办法
查询是否暗转libaio依赖包
#yum search libaio
如果没安装,可以用下面命令安装
#yum install libaio
8、初始化MysqL命令
#cd /software/MysqL/bin
#./MysqLd --user=MysqL --basedir=/software/MysqL --datadir=/data/MysqL --initialize
在执行上面命令时特别要注意一行内容
[Note] A
temporary
password
is
generated
for
[email protected]: o*s#gqh)F4Ck
[email protected]: 后面跟的是MysqL数据库登录的临时密码,各人安装生成的临时密码不一样
如果初始化时报错如下:
error while loading shared libraries: libnuma.so.1: cannot open shared objec
是因为libnuma安装的是32位,我们这里需要64位的,执行下面语句就可以解决
#yum install numactl.x86_64
执行完后重新初始化MysqL命令
9、启动MysqL服务
# sh /software/MysqL/support-files/MysqL.server start
上面启动MysqL服务命令是会报错的,因为没有修改MysqL的配置文件,报错内容大致如下:
if test -z "$basedir"
then
basedir=/usr/local/MysqL
bindir=/usr/local/MysqL/bin
if test -z "$datadir"
then
datadir=/usr/local/MysqL/data
fi
sbindir=/usr/local/MysqL/bin
libexecdir=/usr/local/MysqL/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
修改后
if test -z "$basedir"
then
basedir=/software/MysqL
bindir=/software/MysqL/bin
if test -z "$datadir"
then
datadir=/data/MysqL
fi
sbindir=/software/MysqL/bin
libexecdir=/software/MysqL/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
保存退出
#vi /etc/my.cnf
[client]
no-beep
socket =/software/MysqL/MysqL.sock
# pipe
# socket=0.0
port=3306
[MysqL]
default-character-set=utf8
[MysqLd]
basedir=/software/MysqL
datadir=/data/MysqL
port=3306
pid-file=/software/MysqL/MysqLd.pid
#skip-grant-tables
skip-name-resolve
socket = /software/MysqL/MysqL.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/MysqL
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_Metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
保存退出
12、启动MysqL
#/etc/init.d/MysqLd start
Starting MysqL.Logging to ‘/data/MysqL/SZY.err‘.
2018-07-02T10:09:03.779928Z MysqLd_safe The file /usr/local/MysqL/bin/MysqLd
does not exist or is not executable. Please cd to the MysqL installation
directory and restart this script from there as follows:
./bin/MysqLd_safe&
See http://dev.MysqL.com/doc/MysqL/en/MysqLd-safe.html for more information
ERROR! The server quit without updating PID file (/software/MysqL/MysqLd.pid).
因为新版本的MysqL安全启动安装包只认/usr/local/MysqL这个路径。
解决办法:
方法1、建立软连接
例 #cd /usr/local/MysqL
#ln -s /sofware/MysqL/bin/myslqd MysqLd
方法2、修改MysqLd_safe文件(有强迫症的同学建议这种,我用的这种)
# vim /software/MysqL/bin/MysqLd_safe
将所有的/usr/local/MysqL改为/software/MysqL
#/software/MysqL/bin/MysqL -u root –p
14、输入临时密码。临时密码就是第8条[email protected]:后面的内容
>MysqL set password=password(‘root‘);
>MysqL grant all privileges on *.* to [email protected]‘%‘ identified by ‘root‘;
>MysqL flush privileges;
16、完成,此时MysqL的登录名root 登录密码root
转载自:https://www.cnblogs.com/shizhongyang/p/8464876.html