MySQL5.7升级到8.0

一、二进制包类升级

1.下载二进制包和检测升级工具

wget http://mirrors.e6.e6gpshk.com/centos/7/download/mysql-8.0.23-el7-x86_64.tar.gz  --二进制包集合
mysql-shell-8.0.23-1.el7.x86_64.rpm  --检测是否可以正常升级

2.安装mysql-shell,检测数据库

rpm -ivh mysql-shell-8.0.23-1.el7.x86_64.rpm

mysqlsh root:[email protected]:3306 -e "util.checkForServerUpgrade();"
--检测到error为0就可以正常升级了

3.字符集注意事项

数据库字符集若是为UTF8则需要指定参数文件字符集,MySQL8.0默认UTF8mb4

vim /etc/my.cnf

[client]
default-character-set=utf8

...
[mysqld]
...
character-set-client-handshake = FALSE
character-set-server = utf8
collation-server = utf8_unicode_ci
init_connect='SET NAMES utf8'
...

4.关闭MySQL实例,备份mysql

service mysqld stop
cp -r /data/mysql /data/mysql_5.7_databak

5.解压二进制包,替换历史二进制文件

tar -zxvf mysql-8.0.23-el7-x86_64.tar.gz
mv mysql-8.0.23-el7-x86_64 /usr/local/
mv /usr/local/mysql /usr/local/mysql_5.7
mv /usr/local/mysql-8.0.23-el7-x86_64 /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

6.启动myql,MySQL8.0自动升级

service mysqld start

--可以查看MySQL错误日志,看到MySQL在启动后自动升级了MySQL字典
cat /var/log/mysqld.log

二、rpm包类升级

1.下载rpm包和检测升级工具

wget http://mirrors.e6.e6gpshk.com/centos/7/download/mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
wget http://mirrors.e6.e6gpshk.com/centos/7/download/mysql-shell-8.0.23-1.el7.x86_64.rpm
mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar  --二进制包集合
mysql-shell-8.0.23-1.el7.x86_64.rpm  --检测是否可以正常升级

2.安装mysql-shell,检测数据库

rpm -ivh mysql-shell-8.0.23-1.el7.x86_64.rpm

mysqlsh [email protected]:3307 -e "util.checkForServerUpgrade();"

mysqlsh root:vj7GKXV*[email protected]:4336 -e "util.checkForServerUpgrade();"

--检测到error为0就可以正常升级了

--检测到两个错误
20) Issues reported by 'check table x for upgrade' command
  Notice  : Table (dataxweb.vw_datax_web) - No database selected
  Error   : Table (dataxweb.vw_datax_web) - Corrupt
  Notice  : Table (e6managerdb.vw_datax_web) - No database selected
  Error   : Table (e6managerdb.vw_datax_web) - Corrupt

  Errors:   2
  Warnings: 632
  Notices:  4

  2 errors were found. Please correct these issues before upgrading to avoid compatibility issues.
--视图中含有跨库子查询,可以忽略

3.字符集注意事项

数据库字符集若是为UTF8则需要指定参数文件字符集,MySQL8.0默认UTF8mb4

vim /etc/my.cnf

[client]
default-character-set=utf8

...
[mysqld]
...
character-set-client-handshake = FALSE
character-set-server = utf8
collation-server = utf8_unicode_ci
init_connect='SET NAMES utf8'
...

4.关闭MySQL实例,备份mysql

service mysqld stop
cp -r /data/mysql /data/mysql_5.7_databak

5.卸载5.7rpm包

rpm -qa |grep mysql -i

mysql-community-devel-5.7.29-1.el7.x86_64
php-mysql-5.4.16-48.el7.x86_64
perl-DBD-MySQL-4.023-6.el7.x86_64
--mysql-shell-8.0.23-1.el7.x86_64
mysql-community-client-5.7.29-1.el7.x86_64
mysql-community-libs-compat-5.7.29-1.el7.x86_64
mysql-community-libs-5.7.29-1.el7.x86_64
mysql-community-common-5.7.29-1.el7.x86_64
mysql-community-server-5.7.29-1.el7.x86_64

以上全部卸载
 yum remove  mysql
 rpm -e mysql-community-devel-5.7.29-1.el7.x86_64
 rpm -e php-mysql-5.4.16-48.el7.x86_64
 rpm -e percona-xtrabackup-24-2.4.17-1.el7.x86_64
 rpm -e perl-DBD-MySQL-4.023-6.el7.x86_64 --nodeps
 rpm -e mysql-community-libs-5.7.29-1.el7.x86_64
 rpm -e mysql-community-libs-compat-5.7.29-1.el7.x86_64
 rpm -e mysql-community-libs-5.7.29-1.el7.x86_64
 rpm -e mysql-community-common-5.7.29-1.el7.x86_64

删除残余
whereis mysql
rm -r  /usr/share/mysql

--安装8.0.23的rpm包

 rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm 
 rpm -ivh mysql-community-client-plugins-8.0.23-1.el7.x86_64.rpm 
 rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm
 rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm 
 rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm 
 rpm -ivh mysql-community-devel-8.0.23-1.el7.x86_64.rpm --可不安装
 rpm -ivh mysql-community-libs-compat-8.0.23-1.el7.x86_64.rpm --可不安装
 rpm -ivh mysql-community-embedded-compat-8.0.23-1.el7.x86_64.rpm --可不安装
 rpm -ivh mysql-community-test-8.0.23-1.el7.x86_64.rpm --可不安装

--安装之前卸载的rpm(不知道哪个工具会用,最好再给安装上)
yum install php-mysql 
yum install perl-DBD-MySQL

6.启动myql,MySQL8.0自动升级

service mysqld start

配置文件修改
1.innodb_file_format=barracuda --表压缩不被识别,默认为压缩格式
2.expire-logs-days 改为 binlog_expire_logs_seconds=2592000 --#保留30天
3.skip-name-resolve  --跳过反向解析
4.default_authentication_plugin=mysql_native_password  --使用历史密码认证方式


--可以查看MySQL错误日志,看到MySQL在启动后自动升级了MySQL字典
cat /var/log/mysqld.log

你可能感兴趣的:(MySQL,linux,centos,服务器)