这里有最新的使用文档和教程
操作系统:CentOS 7.x
MySQL二进制版本:5.7.x 小版本升级
现有版本:MySQL 5.7.38
升级后版本:MySQL 5.7.39
下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
上传mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz到/usr/local/src
升级前先查看MySQL 5.7.x 中添加、弃用或删除的变量和选项
https://dev.mysql.com/doc/refman/5.7/en/added-deprecated-removed.html
############################################
MySQL 8.0.x版本可以使用mysql-shell进行升级前的检查
mysql-shell-8.0.29-linux-glibc2.12-x86-64bit.tar.gz
https://cdn.mysql.com/archives/mysql-shell/mysql-shell-8.0.29-linux-glibc2.12-x86-64bit.tar.gz
tar zxvf /usr/local/src/mysql-shell-8.0.29-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
cd /usr/local
mv mysql-shell-8.0.29-linux-glibc2.12-x86-64bit mysql-shell
cd /usr/local/mysql-shell/bin
./mysqlsh -- util checkForServerUpgrade root@localhost:3306 --target-version=5.7.39 --output-format=JSON --config-path=/data/server/mysql/my.cnf
############################################
使用离线方式进行升级
一、主库操作
1、进入mysql控制台
set global innodb_fast_shutdown=0; #保障数据的完整性
flush tables with read lock; #数据库只读锁定命令,防止导出数据库的时候有数据写入(命令执行期间控制台不能关闭,控制台关闭命令就自动失效了,unlock tables;#解除锁定)
set global read_only=on; #设置数据库为只读(数据库重启之后命令失效,set global read_only=off;#解除锁定)
2、备份数据
#重启打开一个终端进行操作
/data/server/mysql/bin/mysqldump -h 127.0.0.1 -u root -p lts --default-character-set=utf8mb4 --opt -Q -R --skip-lock-tables> /tmp/lts-bak.sql
3、停止mysql
/data/server/mysql/mysql.sh stop
4、安装新版mysql
#备份mysql安装目录和数据库目录(mysql数据库目录在/data/server/mysql/data下)
mv /data/server/mysql /data/server/mysql.bak
#创建新版数据库安装目录
mkdir -p /data/server/mysql
#解压新版软件到安装目录
cd /usr/local/src/
tar zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz -C /data/server/mysql --strip-components 1
#拷贝旧版数据存放目录、my.cnf配置文件、mysql启动脚本到新版数据库安装目录
cp -r /data/server/mysql.bak/data /data/server/mysql/
cp -r /data/server/mysql.bak/my.cnf /data/server/mysql/
cp -r /data/server/mysql.bak/mysql.sh /data/server/mysql/
#注意权限保持一致
chown mysql.mysql /data/server/mysql -R
#编辑配置文件,注释掉主从同步的配置参数
vi /data/server/mysql/my.cnf
#log-bin=mysql-bin
#binlog-do-db=lts
#binlog-ignore-db=mysql
:wq! #保存退出
#启动mysql
/data/server/mysql/bin/mysqld_safe --defaults-file=/data/server/mysql/my.cnf --user=mysql --port=3306 --basedir=/data/server/mysql --datadir=/data/server/mysql/data --socket=/data/server/mysql/data/mysql.sock --pid-file=/data/server/mysql/data/mysql.pid --skip-grant-tables --skip-networking &
注:–skip-grant-tables和–skip-networking参数,来保证没有任何的应用连接,让升级过程更加安全。
#查看数据库是否正常启动
ps -ef |grep mysqld
5、升级系统表数据字典信息
/data/server/mysql/bin/mysql_upgrade
[root@mysql-master mysql]# /data/server/mysql/bin/mysql_upgrade
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.2).
Checking databases.
lts.lts_cron_job_queue OK
lts.lts_executing_job_queue OK
lts.lts_fjq_test_jobclient OK
lts.lts_job_log_po OK
lts.lts_node_group_store OK
lts.lts_repeat_job_queue OK
lts.lts_suspend_job_queue OK
lts.lts_wjq_test_trade_tasktracker OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
6、登录到数据库查看版本