mysql升级可以用mysql_upgrade更新系统库,5.7版本的系统库和5.6差别巨大,这种方式有诸多风险,没有尝试,这里采取另外一种方式。

5.7版本的安装目录和数据目录,都重新指定,和5.6区分开,5.7安装过程如下:

mkdir /data/mysql57
chmod +w /data/mysql57
chown -R mysql:mysql /data/mysql57

mysql.com下载带boost的源码包,解压

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5710 -DMYSQL_DATADIR=/data/mysql57 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR==/data/mysql57/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/usr/local/src/mysql-5.7.16/boost
make
make install

完成安装,接下来初始化5.7系统库,初始化前注意原my.cnf配置文件,很多配置项和5.7不兼容了,先另存,改成5.7默认配置文件

初始化系统库

/usr/local/mysql5710/bin/mysqld –initialize –user=mysql

记住初始化后的给的默认密码,后面首次登录会用到

启动mysql

/usr/local/mysql5710/bin/mysqld_safe &

客户端登录mysql

/usr/local/mysql5710/bin/mysql -h 127.0.0.1 -u root -p

输入密码

提示:You must reset your password using ALTER USER statement before executing this statement.

直接修改密码:

SET PASSWORD = PASSWORD(’123456′);

进入mysql库,修改几个innodb表引擎,方便后面直接覆盖ibdata1文件

alter table engine_cost engine=’myisam’;
alter table gtid_executed engine=’myisam’;
alter table help_category engine=’myisam’;
alter table help_keyword engine=’myisam’;
alter table help_relation engine=’myisam’;
alter table help_topic engine=’myisam’;
alter table innodb_index_stats engine=’myisam’;
alter table innodb_table_stats engine=’myisam’;
alter table plugin engine=’myisam’;
alter table server_cost engine=’myisam’;
alter table servers engine=’myisam’;
alter table slave_master_info engine=’myisam’;
alter table slave_relay_log_info engine=’myisam’;
alter table slave_worker_info engine=’myisam’;
alter table time_zone engine=’myisam’;
alter table time_zone_leap_second engine=’myisam’;
alter table time_zone_name engine=’myisam’;
alter table time_zone_transition engine=’myisam’;
alter table time_zone_transition_type engine=’myisam’;

停掉mysql

将5.6数据目录的ibdata1和数据库目录转移到5.7数据目录下

注意转移过来文件的写权限

再次启动mysql

将系统表几个改成myisam引擎的表再改回innodb,至此完美升级完mysql,且最快恢复数据,直接拷贝数据文件,比mysqldump导sql再导入快多了