1. 备份数据
备份数据库
执行备份命令:
innobackupex --defaults-file=/etc/my.cnf --host=localhost --user=backuxxer --password=xxuser /opt/xxx/backup/mysql
或者执行脚本备份:
/opt/x/mysql/scripts/mysqlback_temp.sh
停止MySQL 5.6
/opt/xx/init.d/mysql stop
备份MySQL相关目录
把所有MySQL相关目录mv到其他路径或者重命名:
mv /opt/xx/db/mysql /opt/xxxx/db/mysql_bak`date +%Y%m%d`
mv /opt/xeix/conf/mysql /opt/xxxix/conf/mysql_bak`date +%Y%m%d`
mv /opt/xix/logs/mysql /opt/xxxxx/logs/mysql_bak`date +%Y%m%d`
mv /opt/xx/run/mysql /opt/bxxxxx/run/mysql_bak`date +%Y%m%d`
mv /opt/bxx/scripts/mysql /opt/bxxxxix/scripts/mysql_bak`date +%Y%m%d`
2. 安装MySQL 5.7 bin包
安装完后,会自动创建上一步中所述的目录,并且MySQL 5.7会自动启动。先把MySQL 5.7停止
/opt/blxx/init.d/mysql stop
3.还原数据目录,并执行mysql_upgrade
还原数据目录
mv /opt/xx/db/mysql /opt/xxxix/db/mysql_new`date +%Y%m%d`
mv /opt/xx/db/mysql_bak`date +%Y%m%d` /opt/xxx/db/mysql
修改my.cnf
比较新老配置文件中innodb_buffer_pool_size这个参数,使新旧一致,旧配置文件路径为:/opt/xxxx/conf/mysql_bak`date +%Y%m%d`/my-master.cnf
执行mysql_upgrade
/opt/xxxxx/init.d/mysql start
mysql_upgrade -uroot -p
修改/etc/crontab文件
删除这行:
0 1 * * * root /opt/xxix/mysql/scripts/mysqlback.sh
4. 重启MySQL 5.7
/opt/xix/init.d/mysql restart
5. 更改timestamp类型字段默认值
把数据库里表结构中timestamp类型的默认值由'0000-00-00 00:00:00'改成CURRENT_TIMESTAMP
mysql -uroot -p -e "
select replace(alter_sql,',',', modify ')
from(select concat('alter table ',TABLE_SCHEMA,'.',TABLE_NAME,' modify ',
group_concat(COLUMN_NAME,' timestamp default CURRENT_TIMESTAMP'),';') alter_sql
from information_schema.COLUMNS
where COLUMN_DEFAULT = '0000-00-00 00:00:00'
and TABLE_SCHEMA not in('performance_schema','mysql','information_schema','sys')
group by TABLE_SCHEMA,TABLE_NAME) t into outfile '/tmp/alter.sql'"
mysql -uroot -p < /tmp/alter.sql
可用如下SQL查询是否还有需要修改的字段:
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE
from information_schema.COLUMNS
where COLUMN_DEFAULT = '0000-00-00 00:00:00'
and TABLE_SCHEMA not in('performance_schema','mysql','information_schema','sys');
6. 更改某些字段的NULL属性
mysql -uroot -p -e "
use guxnxg;
alter table account_t modify column current_cycle_end timestamp NULL DEFAULT CURRENT_TIMESTAMP,modify column current_cycle_start timestamp NULL DEFAULT CURRENT_TIMESTAMP;
alter table location_share_session_t modify column end_time timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '结束时间';
alter table xxxg.favorite_t modify content longtext CHARACTER SET utf8mb4;
use gxgwexxb;
alter table bind_pic_t modify column create_time timestamp NULL DEFAULT CURRENT_TIMESTAMP;"
7. 其他
如果MySQL中有短信模块的库,执行如下命令:
use sms_provider;
alter table sms_record_t modify column recieve_time timestamp NULL DEFAULT CURRENT_TIMESTAMPalter table sms_record_t modify column send_time timestamp NULL DEFAULT CURRENT_TIMESTAMP
如果有通讯录同步程序的环境,还需执行如下命令:
use gxxong;
update docking_org_info_config_t set struct_fileds = 'name,structId,structParentId,action,level,category,longCode,longPath,status,seq';
update docking_org_info_config_t set member_fileds = 'name,memberId,structId,action,mobile,email,position,job,business,telephone,fax,address,longCode,longPath,status,seq,role,register,serialNumber,contactEx';
注意,sql为update语句,没有通讯录同步的项目执行会报错。