背景介绍:
由于安全漏扫,发现现网数据库mysql5.6.37存在多处安全漏洞,应客户方要求,需要对现网的数据库版本进行升级到5.7.20以上。
mysql5.6升级mysql5.7
说明:
本次升级是以mysql5.7.27的二进制安包为版本,从而可以避免较长时间的源码编译。
升级前:
版本为5.6.37
有数据库iam
数据库中有数据
数据库中有其他用户
升级操作步骤:
step1:下载mysql5.7.26的 二进制安装包,并上传指定目录
下载地址:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.27.tar.gz
step2:解压到指定目录并更改安装包的属性
cd /opt/
tar -xf mysql-5.7.27.tar.gz -C /usr/local/ && cd /usr/local/
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql57 && chown -R mysql.mysql mysql57
step3:备份原来的数据库
/etc/init.d/mysqld stop #关闭数据库(涉及主从同步的话,建议先关闭主从同步进程,再停掉主数据库)
ps -ef | grep mysqld | grep -v grep #确认不存在mysql进程
cp -rf -p /u01/mysql/data /u01/mysql/data_5.6 #备份数据文件
cp -p /etc/my.cnf /etc/my.cnf_5.6 #备份配置文件
cp -p /etc/init.d/mysqld /etc/init.d/mysqld_5.6 #备份启停脚本
step4:修改配置文件
将/etc/my.cnf文件中的
"basedir = /usr/local/mysql"替换成"basedir = /usr/local/mysql57"
"myisam_recover" 注释掉
"innodb_additional_mem_pool_size" 注释掉
step5:启动服务
cd /usr/local/mysql57/bin
./mysqld --defaults-file=/etc/my.cnf &
/var/log/mysql/mysql_error.log
step6:升级数据库(升级数据字典)
cd /usr/local/mysql57/bin
./mysql_upgrade -s -uroot -p123456 #加-s只会更新系统的表,不去更新数据
step7:重启mysql数据库
先关闭数据库
./mysqladmin -uroot -p123456 -S /tmp/mysql.sock shutdown
再启动数据库
cd /usr/local/mysql57
cp support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
step8:建立软连接
ll /usr/bin/mysql 查看老版本的mysql连接
unlink /usr/bin/mysql 解除老版本的mysql连接
ln -s /usr/local/mysql57/bin/mysql /usr/bin/mysql 新建新版本的连
或
将mysql5.7的安装包路径放入/etc/profile做环境变量,source /etc/profile即可
step9:验证版本,数据(如果涉及有主从同步的,只需要重新再坐下主从配置即可)
问题处理:
1、升级后引发调用数据库的程序出现异常报错
解决办法:在mysql的配置文件中/etc/my.cnf的[mysqld]下面添加如下配置项,然后重启数据库服务即可
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
2、5.6.37数据库启动时报错
[Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead
[Note] Plugin 'FEDERATED' is disabled.
InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
大概意思是唯一的选项myisam_recover而不是myisam-recover-options将会弃用或者移除,请使用全名,即配置请使用myisam-recover-options
插件FEDERATED是禁用,即需要配置federated
innodb_additional_mem_pool_size 将会弃用,以后可能会被移除,同时innodb_use_sys_malloc和InnoDB’s自带的内存分配将不再需要
Memory barrier is not used 即内存不够,因为本人虚拟机的内存是2G,初始化时给buffer pool
分配了2G,导致内存不够
解决办法:
根据提示,只需修改配置文件 /etc/mysql/my.cnf 中 参数名 myisam-recover为myisam-recover-options 即可;
同时注释掉innodb_additional_mem_pool_size = 32M配置项或者将调小;
在mysql的配置文件中的[mysqld]下添加配置federated即可;
最后改完保存重启服务。
#innodb_additional_mem_pool_size = 32M
innodb_buffer_pool_size = 4M