MySQL 5.6.40 升级到 MySQL 8.0.11 指南
环境
- 操作系统:rhel7.5
目标
将 MySQL 5.6.22 升级到 MySQL 8.0.11
错误提示
直接从 MySQL 5.6.40 升级到 MySQL 8.0.11 会导致启动错误,不支持 redo log format:
2018-07-08T09:42:27.773497Z 1 [ERROR] [MY-013090] [InnoDB] InnoDB:
Unsupported redo log format (0). The redo log was created before MySQL
5.7.9
2018-07-08T09:42:27.773552Z 1 [ERROR] [MY-012930]
[InnoDB] InnoDB: Plugin initialization aborted with error Generic error.
2018-07-08T09:42:28.377597Z 1 [ERROR] [MY-011013] [Server] Failed to initialize DD Storage Engine.
2018-07-08T09:42:28.378527Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2018-07-08T09:42:28.378601Z 0 [ERROR] [MY-010119] [Server] Aborting
正确的升级路径
mysql5.6.40 --> mysql5.7.22 --> mysql8.0.11
具体步骤
1. 准备步骤
- 建立软件存储目录
mkdir /setup/mysql
- 建立软件及数据目录
mkdir /data/db -p
mkdir /mysql
- 建立mysql组和用户
groupadd mysql
useradd -g mysql mysql
- 修改权限
chown -R mysql:mysql /data/db /mysql
chmod -R 775 /data/db /mysql
- 软件上传到 /setup/mysql
ls -ltr /setup/mysql
- 解压软件并切换到mysql用户登录
su - mysql
cd /mysql
- 解压5.6.40
tar xzvf /setup/mysql/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /mysql
mv mysql-5.6.40-linux-glibc2.12-x86_64 mysql-5.6.40
- 解压5.7.22
tar xzvf /setup/mysql/mysql-5.7.22-el7-x86_64.tar.gz -C /mysql
mv mysql-5.7.22-el7-x86_64 mysql-5.7.22
- 解压8.0.11
tar xzvf /setup/mysql/mysql-8.0.11-el7-x86_64.tar.gz -C /mysql
mv mysql-8.0.11-el7-x86_64 mysql-8.0.11
2. 启动5.6.40
cd /mysql/mysql-5.6.40
- 初始化mysql --以 mysql用户完成
$ ./scripts/mysql_install_db--basedir=/mysql/mysql-5.6.40 --datadir=/data/db/ --log-error=/data/db/mysql-error.log --socket=/data/db/mysql.sock --user=mysql
启动mysql server:
$ ./bin/mysqld_safe--basedir=/mysql/mysql-5.6.40 --datadir=/data/db/ --log-error=/data/db/mysql-error.log --socket=/data/db/mysql.sock &
修改mysql实例root口令:
./bin/mysqladmin -uroot -S/data/db/mysql.sock password 'mysql'
3. MySQL 5.6.40升级到5.7.22
3.1 停 mysql server 5.6:
$ cd /mysql/mysql-5.6.40
$ ./bin/mysql -uroot -p -S /data/db/mysql.sock
修改global变量innodb_fast_shutdown=0:
mysql> set global innodb_fast_shutdown=0;
- 关闭数据库
$ ./bin/mysqladmin -uroot -p -S/data/db/mysql.sock shutdown
3.2 通过mysql server 5.7启动mysql实例:
$ cd /mysql/mysql-5.7.22
$ ./bin/mysqld_safe--socket=/data/db/mysql.sock --basedir=/mysql/mysql-5.7.22 --datadir=/data/db/ --log-error=/data/db/mysql-error.log &
3.3 确认mysql已经启动,日志中数据库已经启动
$ ps -ef|grep mysql
$ tail -100f /data/db/mysql-error.log
2018-07-09T04:24:20.041509Z 0 [Note] /mysql/mysql-5.7.22/bin/mysqld: ready for connections.
Version: '5.7.22' socket: '/data/db/mysql.sock' port: 3306 MySQL Community Server (GPL)
3.4 升级.mysql实例数据字典:
$ ./bin/mysql_upgrade -uroot -p -S/data/db/mysql.sock
下面是过程信息:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
...
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
3.5 重启mysql 5.7实例:
./bin/mysqladmin -uroot -p -S/data/db/mysql.sock shutdown
./bin/mysqld_safe --socket=/data/db/mysql.sock --basedir=/mysql/mysql-5.7.22 --datadir=/data/db/ --log-error=/data/db/mysql-error.log &
3.6 检查升级后mysql server版本:
./bin/mysql -uroot -pmysql -S /data/db/mysql.sock
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.22 |
+-----------+
1 row in set (0.00 sec)
- 还应该检查日志文件,是否有错误出现。
到5.7.22的升级结束
4. MySQL 5.7.22升级到8.0.11
4.1 先修改 innodb_fast_shutdown =0
$ cd /mysql/mysql-5.7.22
$ ./bin/mysql -uroot -p -S /data/db/mysql.sock
mysql> set global innodb_fast_shutdown=0;
4.2 停 mysql server 5.7
cd /mysql/mysql-5.7.22
$ ./bin/mysqladmin -uroot -p -S/data/db/mysql.sock shutdown
4.3 通过mysql server 8.0.11启动mysql实例:
$ cd /mysql/mysql-8.0.11
$ ./bin/mysqld_safe--socket=/data/db/mysql.sock --basedir=/mysql/mysql-8.0.11 --datadir=/data/db/ --log-error=/data/db/mysql-error.log &
4.4 确认mysql已经启动,日志中数据库已经启动
$ ps -ef|grep mysql
$ tail -100f /data/db/mysql-error.log
[System] [MY-010931] [Server] /mysql/mysql-8.0.11/bin/mysqld: ready for connections. Version: '8.0.11' socket: '/data/db/mysql.sock' port: 3306 MySQL Community Server - GPL.
4.5 升级.mysql实例数据字典
$ cd /mysql/mysql-8.0.11
$ ./bin/mysql_upgrade -uroot -p -S/data/db/mysql.sock
下面是过程信息:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
...
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
以下是根据您的要求调整后的Markdown格式文章:
4.6 重启 MySQL 8.0.11 实例
$ cd /mysql/mysql-8.0.11
$ ./bin/mysqladmin -uroot -p -S/data/db/mysql.sock shutdown
$ ./bin/mysqld_safe --socket=/data/db/mysql.sock --basedir=/mysql/mysql-8.0.11 --datadir=/data/db/ --log-error=/data/db/mysql-error.log &
4.7 检查升级后 MySQL Server 版本:
$ cd /mysql/mysql-8.0.11
./bin/mysql -uroot -pmysql -S /data/db/mysql.sock
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.11 |
+-----------+
1 row in set (0.00 sec)
还应该检查日志文件,是否有错误出现。
到此,5.6.40 升级到 8.0.11 全部完成。
此内容引用自 MySQL 5.6.40 升级到 MySQL 8.0.11 的步骤