安装sql shell检查升级兼容问题。
rpm -ivh mysql-shell-8.0.35-1.el7.x86_64.rpm
默认安装路径/usr/bin,执行./mysqlsh 链接命令工具,再执行util.checkForServerUpgrade('root@localhost:3306',{"targetVersion":"8.0.34"})命令,输出兼容问题。输入\q退出
停止所有应用后再停止mysql服务
备份mysql数据库
下载mysql8手动安装包
修改my.cnf配置文件
因5.7版本与8.0版本参数有所不同,为了能顺利升级,我们需要更改部分配置参数。主要注意sql_mode、basedir、密码认证插件及字符集设置,其他参数最好还是按照原5.7的来,不需要做调整。下面展示5.7(左)和8.0(右)的配置文件,注意备份原来配置文件。
[mysql]
socket=/tmp/mysql.sock
default-character-set=utf8
[mysqld]
user=mysql
basedir=/home/application/mysql/app
datadir=/home/application/mysql/data
character_set_server=utf8
collation-server=utf8_general_ci
#日志时间
log_timestamps=SYSTEM
port=3306
socket=/tmp/mysql.sock
max_connections=1000
max_allowed_packet=500M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#慢日志
long_query_time=3
slow_query_log=ON
slow_query_log_file=/home/application/mysql/slow_query.log
#错误日志
log-error=/home/application/mysql/mysql-error.log
#binlog配置
server_id=150
log-bin=mysql-bin
max_binlog_size = 100M
binlog_format=row
log_slave_updates
expire_logs_days=7
#只能用IP地址检查客户端的登录,不用主机名
skip-name-resolve=1
[mysql]
socket=/tmp/mysql.sock
default-character-set=utf8
[mysqld]
user=mysql
#日志时间
log_timestamps=SYSTEM
port=3306
socket=/tmp/mysql.sock
max_connections=1000
max_allowed_packet=500M
#只能用IP地址检查客户端的登录,不用主机名
skip-name-resolve=1
#binlog配置
server_id=150
log-bin=mysql-bin
max_binlog_size = 100M
binlog_format=row
log_slave_updates
expire_logs_days=7
#慢日志
long_query_time=3
slow_query_log=ON
slow_query_log_file=/home/application/mysql/slow_query.log
#错误日志
log-error=/home/application/mysql/mysql-error.log
#for8.0
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
basedir=/home/application/mysql/mysql8
datadir=/home/application/mysql/data
character_set_server=utf8
collation-server=utf8_general_ci
# 默认使用"mysql_native_password"插件认证
default_authentication_plugin=mysql_native_password
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
执行升级程序
[root@srebro.cn ~]# /home/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --upgrade=FORCE
2023-10-30T07:33:23.595626Z mysqld_safe Logging to '/home/ mysql8/mysql-error.log'.
2023-10-30T07:33:23.620303Z mysqld_safe Starting mysqld daemon with databases from /home/application/mysql/data
# 可能会一直卡住不用担心,新开一个窗口观察下错误日志看是否报错/home/mysql8/mysql-error.log 然后登录数据库测试
修改mysql环境变量
由于basedir 从/home/application/mysql/app 变成了 /home/mysql8,需要修改下环境变量信息