記事のディレクトリ
データベースアップグレードの2つの方法
方法1:
mysql5.6.48アップグレードmysql5.7.30
1.mysql5.6.xを停止します
/* 在停止之前,记录sql_mode值,动态修改innodb_fast_shutdown=0 */
mysql> show variables like '%sql_mode%';
+---------------+--------------------------------------------+
| Variable_name | Value |
+---------------+--------------------------------------------+
| sql_mode | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+---------------+--------------------------------------------+
1 row in set (0.00 sec)
mysql> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)
/* innodb_fast_shutdown参数含义:
全局选项,可以取值为0 1 2 默认选项为1
当此值为0时,表示mysql慢关机,将内存缓冲区里的数据清除和合并之后再关闭
当此值为1时,会跨过这些选项,快速关闭
当此值为2时,相当于mysql宕机,拔电源关机
*/
mysql> exit
Bye
[root@centos7 /usr/local/mysql56/bin]# /usr/local/mysql56/support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!
2.my.cnfファイルにパラメーターを追加します
[mysqld]
basedir=/usr/local/mysql56
datadir=/data/3307/data
user=mysql
server_id=5107
log-error=/data/3307/error.log
log_bin=/data/3307/mysql-bin
skip_name_resolve
port=3307
socket=/data/3307/mysql.sock
skip_grant_tables
3.basedirを交換します
gunzip mysql-5.7.30-xxxx.tar.gz
tar xf mysql-5.7.30-xxxx.tar /opt
ln -s /opt/mysql5.7.30 /usr/local/mysql
[root@centos7 /usr/local]# ll
总用量 0
drwxr-xr-x. 2 root root 45 7月 15 20:54 bin
lrwxrwxrwx. 1 root root 6 9月 17 03:25 data -> /data/
drwxr-xr-x. 3 root root 23 7月 15 20:54 doc
drwxr-xr-x. 2 root root 6 4月 10 2018 etc
drwxr-xr-x. 2 root root 6 4月 10 2018 games
drwxr-xr-x. 4 root root 32 7月 15 20:56 include
drwxr-xr-x. 2 root root 6 4月 10 2018 lib
drwxr-xr-x. 4 root root 118 7月 15 22:48 lib64
drwxr-xr-x. 2 root root 6 4月 10 2018 libexec
lrwxrwxrwx. 1 root root 12 9月 17 04:34 mysql56 -> /opt/mysql57
drwxr-xr-x. 2 root root 6 4月 10 2018 sbin
drwxr-xr-x. 7 root root 81 7月 15 20:54 share
drwxr-xr-x. 2 root root 6 4月 10 2018 src
[root@centos7 /usr/local]#
4.データをバックアップします
[root@centos7 /data/3307/data]# ls
auto.cnf ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema
cp -ar 3307 /tmp/
5.mysqlを起動します
[root@centos7 /usr/local]# /usr/local/mysql56/support-files/mysql.server start
Starting MySQL. SUCCESS!
[root@centos7 /usr/local]# mysql -uroot -p -P3307
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
方法2:mysql_upgrade
1. mysql5.6.48をインストールし、開始します
少し
[root@centos7 /data/3307]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.48-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
/* 记录sql_mode值*/
mysql> show variables like '%sql_mode%';
+---------------+--------------------------------------------+
| Variable_name | Value |
+---------------+--------------------------------------------+
| sql_mode | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+---------------+--------------------------------------------+
1 row in set (0.00 sec)
mysql> flush table with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> set global read_only=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
2.データをバックアップします
[root@centos7 /data/3307]# mysqldump -uroot -p --add-drop-table -R -E -A --force >/data/3307.sql
Enter password:
[root@centos7 /data]# wc -l 3307.sql
904 3307.sql
3.basedirを交換します
[root@centos7 /usr/local]# ln -sf /tmp/mysql57 /usr/local/mysql56
[root@centos7 /usr/local]# ls
bin data doc etc games include lib lib64 libexec mysql56 sbin share src
[root@centos7 /usr/local]# ll
总用量 0
drwxr-xr-x. 2 root root 45 7月 15 20:54 bin
lrwxrwxrwx. 1 root root 6 9月 17 03:25 data -> /data/
drwxr-xr-x. 3 root root 23 7月 15 20:54 doc
drwxr-xr-x. 2 root root 6 4月 10 2018 etc
drwxr-xr-x. 2 root root 6 4月 10 2018 games
drwxr-xr-x. 4 root root 32 7月 15 20:56 include
drwxr-xr-x. 2 root root 6 4月 10 2018 lib
drwxr-xr-x. 4 root root 118 7月 15 22:48 lib64
drwxr-xr-x. 2 root root 6 4月 10 2018 libexec
lrwxrwxrwx. 1 root root 12 9月 17 19:52 mysql56 -> /tmp/mysql57
drwxr-xr-x. 2 root root 6 4月 10 2018 sbin
drwxr-xr-x. 7 root root 81 7月 15 20:54 share
drwxr-xr-x. 2 root root 6 4月 10 2018 src
4.古いバージョンのデータディレクトリをクリアします
[root@centos7 /usr/local]# cp -ar /data/3307 /data/3307.bak
[root@centos7 /data/3307]# rm -rf *
[root@centos7 /data/3307]# mkdir data
[root@centos7 /data/3307]# chown mysql.mysql -R .
5.データの初期化、開始、インポート
[root@centos7 /usr/local/mysql56/bin]# ./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql56 --datadir=/data/3307/data
[root@centos7 /usr/local/mysql56/bin]# /usr/local/mysql56/support-files/mysql.server start
Starting MySQL. SUCCESS!
[root@centos7 /usr/local/mysql56/bin]# mysql -uroot -p </data/3307.sql
Enter password:
6.mysql_upgrade更新データディクショナリ
[root@centos7 /usr/local/mysql56/bin]# mysql_upgrade -uroot -p
Enter password:
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.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.2).
Found 0 sys functions, but expected 22. Re-installing the sys schema.
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
[root@centos7 /usr/local/mysql56/bin]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>