根据数据库漏扫报告所示,拟将mysql5.5+、mysql5.6+版本的数据库,统一升级到mysql 5.7.28。为保证升级可逆,计划原mysql服务不变,在本机安装新版本mysql,区分端口号,同时提供服务。在旧版本导出数据库,导入新版本。确认升级完成后,切换应用端口,停止低版本mysql服务。
具体操作步骤如下:
检查操作系统环境
1、检查硬盘
df -h
free –h
cat/proc/meminfo |grep -i huge
lsb_release -a
cat etc/profile
cat ~/.bash_profile
cat etc/sysctl.conf
cat ect/host
cat etc/security/limits.conf
cat etc/security/limits.d/20-nproc.conf
cat etc/selinux/config
cat etc/pam.d/login
cat sys/kernel/mm/transparent_hugepage/defrag
检查当前mysql环境
1、检查msyql如何安装
rpm –qa|grep –i mysql
which mysql
ps –ef |grep -i mysql
mysql 安装目录、数据文件目录、binlog目录、my.cnf目录、tmp文件目录
4、检查mysql相应参数
show variables like '%sql_mode%'\G
备份当前mysql
1、动态修改innodb_fast_shutdown=0 以执行full purge
mysql -uroot -p
set global innodb_fast_shutdown=0;
flush table with read lock;
set global read_only=on;
mysqldump -u root -p --add-drop-table --routines --events--all-databases –force --set-gtid-purged=OFF> data-for-upgrade.sql
service mysql stop
ps aux|grep mysqld_safe
netstat -ntupl|grep mysqld
安装mysql5.7.28
根据检查情况,在符合条件的目录安装mysql5.7.28。
安全加固
1、删除非root或非localhost的用户。
Mysql安全加固也可以使用命令行工具mysql_secure_installation,根据提示一步步执行即可。
select user,host from mysql.user;
delete from mysql.user whereuser not in (‘mysql.sys’,’mysql.session’,’mysqlxsys’,’root’,’mysql.infoschema’) or host not in (‘localhost’);
select user,host frommysql.user;
set password for ‘root’@’localhost’=password(‘admin’);
flush privileges;
2、删除test数据库、清理mysql.db
Drop database test;
select * from mysql.db\G
Delete from mysql.db where usernot in (‘mysql.sys’,’mysql.session’,’mysqlxsys’,’root’,’mysql.infoschema’) or host not in (‘localhost’);
select user,host frommysql.user;
select * from mysql.db\G
flush privileges;
导入备份
在my.cnf 中加入skip_grant_tables参数,启动mysql,导入sql文件。
mysql -uroot -p--force <data-for-upgrade.sql
echo $?
升级数据字典
mysqlupgrade -uroot –p
所有项目显示都是ok。
验证升级
1、去掉my.cnf中的skip_grant_tables。
2、重启mysql
service mysql restart
systemctl restart mysql
3、登录mysql,测试升级之后能否正常访问
mysql –uroot –p
select user();
select version();
show grants;
show database;
insert 插入测试
升级失败回退
1、启动旧版mysql
service mysql start
2、解锁表
unlock tables。
set global read_only=OFF;
3、测试mysql
selectuser();
selectversion();
showgrants;
showdatabase;
insert插入测试
本公众号是个人学习工作笔记,希望大家发现问题能及时和我本人沟通,希望你与我共同成长。个人微信zgjt12306。
欢迎关注“自学Oracle”
最后修改时间:2019-12-17 12:30:49
文章转载自自学Oracle,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。