MySQL 5.6.46 升级 mysql-5.7.28
#备份数据库
mysqldump -uroot -p -A >/tmp/qiao.sql
冷备份
cp -a /data/3306/data /opt/
#检查备份
ll /tmp/qiao.sql -h
#温柔关闭数据库 并检查
/usr/local/mysql/bin/mysqladmin -uroot -p -S /data/3306/mysql.sock shutdown
netstat -lntup |grep 33
#准备5.7数据库
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz #解压5.7的数据库
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql57 #移动到/usr/目录
#修改配置文件
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
port=3306
socket= /data/3306/mysql.sock
[client]
socket = /data/3306/mysql.sock
修改后
[mysqld]
user=mysql
basedir=/usr/local/mysql57
datadir=/data/3356/data
port=3356
socket= /data/3356/mysql.sock
#启动数据库,忽略授权校验,忽略网络
/usr/local/mysql57/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables --skip-networking & #用5.7的命令加载5.6的数据库数据。
#进入数据库
/usr/local/mysql/bin/mysql_upgrade -S /data/3306/mysql.sock --force
很多OK
Upgrade process completed successfully.
Checking if update is needed.
#检查版本
mysql -uroot -p
Enter password: #输入密码
#检查版本
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
#查看版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.28 |
+-----------+
1 row in set (0.00 sec)
#检查用户
mysql> select user,host,authentication_string from mysql.user;
+------+-----------+-----------------------+
| user | host | authentication_string |
+------+-----------+-----------------------+
| root | localhost | |
| root | qiao8 | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | NULL |
| | qiao8 | NULL |
| qiao | 127.0.0.1 | |
| blog | localhost | |
| qiao | localhost | |
+------+-----------+-----------------------+
9 rows in set (0.00 sec) #5.6里有无用用户,user表会多密码字段。
#检查库,show databases;看库名,5.6里没有sys等。
#重启数据库到正常状态
/usr/local/mysql57/bin/mysqladmin -uroot -p -S /data/3306/mysql.sock shutdown
/usr/local/mysql57/bin/mysqld_safe --defaults-file=/data/3306/my.cnf &
#内部验证、测试人员测试。
#7撤销维护页,正式提供服务。
#以上过程在正式升级前,应该演练,并运维测试新功能,开发\测试对产品内部严格测试.
INPLACE方式升级注意事项
a. 仅支持GA版本之间升级。
b. 不支持直接跨大版本升级。
b. 如果要从5.6升级到5.7,需要先将5.6升级至5.6最新版,然后再升级到5.7。
c. 如果从5.5升级到5.7,先将5.5升级至5.5最新,再从5.5升级到5.6最新,最后再从5.6升级到5.7最新。
d. 回滚方案要提前设计好,一旦升级不成可以回退,不影响业务。
e. 尽可能降低停机时间。
INPLACE方式升级原理过程
1. 安装要升级到的新版本软件2. 备份原数据库的数据3. 关闭原数据库(注意:提前几天挂维护页通知说明)4. 使用新版本软件mysqld “挂” 旧版本数据目录(/etc/my.cnf)启动##(记得加--skip-grant-tables ,--skip-networking) ###高版本软件命令接低版本数据目录。升级系统库文件(mysql,_schema)5. 升级:只是升级系统表。升级时间和数据量无关的,升级速度快。6. 正常重启数据库。7. 验证各项功能是否正常,内测。 1.upgrade反馈结果 2.查看系统表目录结构。 3.登录后查看版本8. 业务恢复。
##https://dev.mysql.com/doc/refman/8.0/en/upgrading.html
(1)项目背景:官方5.6将停止维护,同时为提升业务库性能,使用增强半同步复制,将5.6业务库升级到5.7;(2)实施流程:
0.先线下各种测试,并写好解决方案文档,和公司领导汇报完毕无问题.1.下载解压新版本软件包、做软连接;2.测试机导入全备数据,进行就地升级测试;3.升级后业务功能测试;4.测试环境ok,准备生产库的升级;5.提前通知挂维护页,业务量低谷升级,先升级从库;6.使用高版本软件挂低版本数据目录启动;7.执行mysql_upgrade -S --force升级系统表;8.正常重启数据库;9.启动成功等待主从数据同步,之后将业务转移到从库上;10.之后再进行主库升级,完毕后做从库,这样可降低宕机时间。11.主从环境开始采用after_sync增强半同步复制功能。(3)实施结果:升级成功,业务恢复,降低宕机时间,业务更加健壮安全。