Centos部署MySQL 8.0




01.下载安装程序并安装依赖包:

cd /root/Downloads
wget http://download.wenjun.tk/Mysql/mysql-8.0.16-linux-glibc2.12-x86_64.tar,下载安装程序。

02.添加用户和用户组:

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

03.解压mysql安装包并且修改其名称:

tar -xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar
xz -d mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar -C /usr/local/
mv /usr/local/mysql-8.0.16-linux-glibc2.12-x86_64/ /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql

04.执行初始化脚本:

/usr/local/mysql/bin/mysqld \
--initialize \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

注: 执行初始化脚本之后会生成一个临时密码,妥善保存下来(比如qgDuHKd7w2,6)

05.最小化编辑my.cnf:

vim /etc/my.cnf,输入以下配置:
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/

06.设置服务启动脚本:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

07.启动服务并加入开机自启:

chkconfig mysql on
service mysql start

08.建立对应mysql启动程序的软链接,并建立mysql链接:

ln -s /usr/local/mysql/bin/mysql /usr/bin
mysql -uroot -p'qgDuHKd7w2,6'

注:通过mysql客户端连接服务器,此处使用之前的临时密码。

09.修改mysql中的root用户密码并删除多余用户:

alter user user() identified by "xxxxxxxxx";
create user root@127.0.0.1 identified by 'xxxxxxxxx';
grant all on *.* to root@'127.0.0.1' with grant options;
flush privileges;
exit;

注:添加一个本地管理员,避免禁止反解后不能登录。

10.修改mysql配置文件并重启:

vim /etc/my.cnf,覆盖全部配置:
[mysql]
user='root'
password='xxxxxxxxx'
host='localhost'
default-character-set=utf8mb4
socket=/usr/local/mysql/mysql.sock

[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8mb4
skip-name-resolve
max_connections=1024
wait_timeout=300
interactive_timeout=300
back_log=300
max_allowed_packet=16M

server-id=1
log-bin=/usr/local/mysql/data/mysql-binlog
binlog_format=ROW
binlog_row_image=minimal
sync_binlog=1
expire_logs_days=7

table_open_cache=256
thread_cache_size=16
thread_stack=512K

innodb_file_per_table=1
innodb_buffer_pool_size=128M
innodb_buffer_pool_dump_at_shutdown=1
innodb_rollback_on_timeout=on
innodb_flush_log_at_trx_commit=2 

sort_buffer_size=256K
join_buffer_size=256K
symbolic-links=0 

[mysqld_safe]
log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid

[mysqldump]
user='root'
password='xxxxxxxxx'
host='localhost'
socket=/usr/local/mysql/mysql.sock

11.重新启动mysql并使用客户端连接:

service mysql restart
mysql
文档更新时间: 2020-06-03 19:31   作者:闻骏