MySQL數(shù)據(jù)庫生產(chǎn)環(huán)境的安裝和升級


0. summary

1. 生產(chǎn)環(huán)境如何安裝mysql
.   1.1 innodb_log_file_size說明
.   1.2 使用編輯的my.cnf安裝5.6.31
.   1.3 安裝5.7.13
.       1.3.1 ssl加密
2. MySQL升級
.   2.1 停止數(shù)據(jù)庫
.   2.2 注意datadir參數(shù),改成真實路徑,生產(chǎn)環(huán)境應(yīng)該是和軟件目錄分離的,所以該步驟不需要
.   2.3 unlink mysql并link5.7路徑
.   2.4 使用mysql_upgrade升級數(shù)據(jù)文件
.   2.5 關(guān)于降級

1. 生產(chǎn)環(huán)境如何安裝mysql

參數(shù)文件來自

http://mp.weixin.qq.com/s?__biz=MjM5MjIxNDA4NA==&mid=207854835&idx=1&sn=c998031ae68162faaf7bdfce406ddbac&mpshare=1&scene=1&srcid=1012S1w0GgW2DmnC02qXGsYK#rd

http://mp.weixin.qq.com/s?__biz=MjM5MjIxNDA4NA==&mid=2649737745&idx=1&sn=cb81f7bdd28e69a5e8a338c27f2e38d2&mpshare=1&scene=1&srcid=1010vF2EKGbdOpt70TKFrZ16#rd

github

git clone https://github.com/jdaaaaaavid/mysql_best_configuration

#### 需要注意的參數(shù) ####

[mysqld]                ---- [mysqld], [mysqld-5.7]這種tag表明了下面的配置在什么版本下才生效,[mysqld]下均生效
.....
.....
autocommit = 0              ---- 從5.6版本開始才有的autocommit模式。該參數(shù)在5.5以后才有,安裝5.6的時候要注意先把該參數(shù)注釋掉,等安裝完成后,再行打開,后面會演示。5.7無需預(yù)先注釋
datadir = /mdata/mysql_data     ---- 默認(rèn)在/usr/local/mysql/data下面,權(quán)限一定是mysql:mysql
innodb_undo_logs = 128          ---- 建議在安裝之前就確定好該值,后續(xù)修改比較麻煩
innodb_undo_tablespaces = 3             ---- 建議在安裝之前就確定好該值,后續(xù)修改比較麻煩
innodb_log_group_home_dir = /redolog/   ---- 根據(jù)實際情況修改,權(quán)限一定是mysql:mysql
innodb_undo_directory = /undolog/       ---- 根據(jù)實際情況修改,權(quán)限一定是mysql:mysql
innodb_log_file_size = 4G
log_error = error.log           ---- 指定日志名,默認(rèn)是$hostname.err
innodb_buffer_pool_size = 2G            ---- 建議配置操作系統(tǒng)內(nèi)存的70%

1.1 innodb_log_file_size說明

[root@lab11g data]# du -sh * | sort -n
1.7M    mysql
4.0K    auto.cnf
8.0K    test
13M     ibdata1
16K     lab11g.err
49M     ib_logfile0
49M     ib_logfile1
636K    performance_schema

初始化是49M, 生產(chǎn)環(huán)境推薦用4G, 至少2G. 5.5版本之前innodb有bug, 設(shè)大了會影響恢復(fù)速度。這個bug在5.5已經(jīng)修復(fù)。

1.2 使用編輯的my.cnf安裝

#### 刪除之前安裝的內(nèi)容 ####

[root@lab11g mysql]# rm -rf data/*
[root@lab11g mysql]# ll data
總計 0
[root@lab11g mysql]# ps -ef | grep mysqld
root     16596  5918  0 23:15 pts/2    00:00:00 grep mysqld

#### 編輯配置文件 ####

[mysqld]
########basic settings########
server-id = 11
port = 3306
user = mysql
bind_address = 192.168.1.21     ---- 注意改地址
autocommit = 0
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
#datadir = /data/mysql_data
datadir = /usr/local/mysql/data     ---- 修改目錄

#### 初始化 ####

[root@lab11g mysql]# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...2016-06-25 23:44:16 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
2016-06-25 23:44:16 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
2016-06-25 23:44:16 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
2016-06-25 23:44:16 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 17171 ...

#### 檢查error.err ####

2016-06-25 23:44:16 2b1aba700560 InnoDB: innodb-page-size has been changed from the default value 16384 to 8192.
2016-06-25 23:44:16 17171 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-06-25 23:44:16 17171 [Note] InnoDB: The InnoDB memory heap is disabled
2016-06-25 23:44:16 17171 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-06-25 23:44:16 17171 [Note] InnoDB: Memory barrier is not used
2016-06-25 23:44:16 17171 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-06-25 23:44:16 17171 [Note] InnoDB: Using Linux native AIO
2016-06-25 23:44:16 17171 [Note] InnoDB: Using CPU crc32 instructions
2016-06-25 23:44:16 17171 [Note] InnoDB: Initializing buffer pool, size = 6.0G
2016-06-25 23:44:18 17171 [Note] InnoDB: Completed initialization of buffer pool
2016-06-25 23:44:18 17171 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-06-25 23:44:18 17171 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-06-25 23:44:18 17171 [Note] InnoDB: Database physically writes the file full: wait...
2016-06-25 23:44:18 2b1aba700560  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
2016-06-25 23:44:18 17171 [ERROR] InnoDB: File /redolog/ib_logfile101: 'create' returned OS error 71.
2016-06-25 23:44:18 17171 [ERROR] InnoDB: Cannot create /redolog/ib_logfile101
2016-06-25 23:44:18 17171 [ERROR] Plugin 'InnoDB' init function returned error.
2016-06-25 23:44:18 17171 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-06-25 23:44:18 17171 [Note] Semi-sync replication initialized for transactions.
2016-06-25 23:44:18 17171 [Note] Semi-sync replication enabled on the master.
2016-06-25 23:44:18 17171 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-06-25 23:44:18 17171 [ERROR] Aborting

2016-06-25 23:44:18 17171 [Note] Binlog end
2016-06-25 23:44:18 17171 [Note] unregister_replicator OK
2016-06-25 23:44:18 17171 [Note] ./bin/mysqld: Shutdown complete

#### 注釋掉路徑不存在的undo和redo目錄,并修改redo大小為1G ####

#innodb_log_group_home_dir = /redolog/
#innodb_undo_directory = /undolog/
innodb_log_file_size = 1G

#### 重新刪除之前的文件并重新初始化 ####

[root@lab11g mysql]# rm -rf data/*
[root@lab11g mysql]# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...2016-06-25 23:51:40 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
2016-06-25 23:51:40 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
2016-06-25 23:51:40 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
2016-06-25 23:51:40 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 17357 ...

OK

Filling help tables...2016-06-25 23:52:01 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
2016-06-25 23:52:01 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
2016-06-25 23:52:01 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
2016-06-25 23:52:01 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 17392 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h lab11g password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

[root@lab11g mysql]# ll data
總計 2134304
-rw-rw---- 1 mysql mysql      63378 06-25 23:51 bin.000001
-rw-rw---- 1 mysql mysql    1178981 06-25 23:52 bin.000002
-rw-rw---- 1 mysql mysql         26 06-25 23:52 bin.index
-rw-rw---- 1 mysql mysql       7189 06-25 23:52 error.log
-rw-rw---- 1 mysql mysql        865 06-25 23:52 ib_buffer_pool
-rw-rw---- 1 mysql mysql   12582912 06-25 23:52 ibdata1
-rw-rw---- 1 mysql mysql 1073741824 06-25 23:52 ib_logfile0
-rw-rw---- 1 mysql mysql 1073741824 06-25 23:51 ib_logfile1
drwx------ 2 mysql mysql       4096 06-25 23:51 mysql
drwx------ 2 mysql mysql       4096 06-25 23:51 performance_schema
drwx------ 2 mysql mysql       4096 06-25 23:51 test
-rw-rw---- 1 mysql mysql    7340032 06-25 23:52 undo001
-rw-rw---- 1 mysql mysql    7340032 06-25 23:52 undo002
-rw-rw---- 1 mysql mysql    7340032 06-25 23:52 undo003
[root@lab11g mysql]# /etc/init.d/mysql.server start
Starting MySQL....[確定]

安裝完成,嘗試登陸報錯,如下:

[root@lab11g mysql]# bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@lab11g mysql]# bin/mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

注意這個時候如果去查mysql/user*即mysql.user表的內(nèi)容是空的。

#### 注釋掉autocommit參數(shù) ####

#autocommit = 0

#### 刪除創(chuàng)建內(nèi)容再次初始化 ####

[root@lab11g mysql]# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...2016-06-26 00:11:31 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
2016-06-26 00:11:31 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
2016-06-26 00:11:31 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
2016-06-26 00:11:31 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 18864 ...
OK

Filling help tables...2016-06-26 00:11:50 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
2016-06-26 00:11:50 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
2016-06-26 00:11:50 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
2016-06-26 00:11:50 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 18892 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h lab11g password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server


[root@lab11g mysql]# /etc/init.d/mysql.server start
Starting MySQL...[確定]
[root@lab11g mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.31-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> 

#### 還原autocommit參數(shù)并重新啟動 ####

[root@lab11g mysql]# mysqladmin shutdown
[root@lab11g mysql]# /etc/init.d/mysql.server start
Starting MySQL...[確定]
[root@lab11g mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.31-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> 

1.3 安裝5.7.13

5.7.13的解壓包里沒有包含INSTALL_BINARY, 可以拿MySQL-5.7.9為例,如下:

shell> yum search libaio  # search for info
shell> yum install libaio # install library
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 770 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up        ---- 可選,希望你產(chǎn)生一個ssl的密鑰
shell> chown -R root .
shell> chown -R mysql data mysql-files 
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

#### 前面步驟省略,安裝過程如下 ####

[root@lab11g local]# pwd
/usr/local
[root@lab11g local]# ln -s mysql-5.7.13-linux-glibc2.5-x86_64 mysql
[root@lab11g local]# cd mysql
[root@lab11g mysql]# mkdir mysql-files
[root@lab11g mysql]# chmod 770 mysql-files
[root@lab11g mysql]# chown -R mysql .
[root@lab11g mysql]# chgrp -R mysql .
[root@lab11g mysql]# bin/mysqld --initialize --user=mysql
[root@lab11g mysql]# bin/mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
............................................................................+++
..+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...........................+++
.........................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
................................................................................+++
..............+++
writing new private key to 'client-key.pem'
-----
[root@lab11g mysql]# chown -R root .
[root@lab11g mysql]# chown -R mysql data mysql-files 
[root@lab11g mysql]# bin/mysqld_safe --user=mysql &
[1] 8239
[root@lab11g mysql]# 2016-07-06T01:50:19.169410Z mysqld_safe Logging to '/usr/local/mysql/data/error.log'.
2016-07-06T01:50:19.195888Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@lab11g mysql]# cp support-files/mysql.server /etc/init.d/mysql.server

5.7安裝過程中會產(chǎn)生臨時密碼,登錄時需要,error.log顯示如下:

2016-07-06T09:47:33.258113+08:00 1 [Note] A temporary password is generated for root@localhost: PqPf-whqT7gi

#### 使用臨時密碼嘗試登錄 ####

[root@lab11g mysql]# mysql -p"PqPf-whqT7gi"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-log

Copyright (c) 2000, 2016, 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> use sys
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.    ---- 提示更改密碼
mysql> set password = '123';                                ---- 5.6是set password = password('123');
Query OK, 0 rows affected (5.02 sec)

mysql> set password = 'mysql';
Query OK, 0 rows affected (0.01 sec)

mysql> use sys
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

1.3.1 ssl加密

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.7.13, for linux-glibc2.5 (x86_64) using  EditLine wrapper

Connection id:      2
Current database:   
Current user:       root@localhost
SSL:            Not in use          ---- 這種方式是不會使用ssl方式
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.13-log
Protocol version:   10
Connection:     Localhost via UNIX socket   ---- 本地登錄
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    gb2312
Conn.  characterset:    gb2312
UNIX socket:        /tmp/mysql.sock
Uptime:         1 min 35 sec

需要使用TCP連接方式才會使用,如下:

[root@lab11g mysql]# mysql -h 127.0.0.1 -u root -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
[root@lab11g data]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      
tcp        0      0 192.168.1.21:3306           0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:722                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN  

實際上是因為my.cnf中設(shè)置了bind_address. 注釋掉bind_address

#bind_address = 192.168.1.21

再次嘗試登錄

[root@lab11g mysql]# mysql -h 127.0.0.1 -u root -p
Enter password: 
ERROR 1130 (HY000): Host '127.0.0.1' is not allowed to connect to this MySQL server

上面報錯是因為沒有這個用戶,后面會說。建立用戶并登錄,如下:

mysql> create user 'root'@'127.0.0.1' identified by 'mysql';
Query OK, 0 rows affected (5.01 sec)

mysql> exit
Bye
[root@lab11g mysql]# mysql -h 127.0.0.1 -u root -p
Enter password: 
......

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.7.13, for linux-glibc2.5 (x86_64) using  EditLine wrapper

Connection id:      6
Current database:   
Current user:       root@127.0.0.1
SSL:            Cipher in use is DHE-RSA-AES256-SHA             ---- 使用了ssl加密
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.13-log MySQL Community Server (GPL)
Protocol version:   10
Connection:     127.0.0.1 via TCP/IP                        ---- TCP連接方式
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    gb2312
Conn.  characterset:    gb2312
TCP port:       3306
Uptime:         2 hours 16 min 12 sec

Threads: 1  Questions: 49  Slow queries: 0  Opens: 146  Flush tables: 1  Open tables: 139  Queries per second avg: 0.005
--------------

更多可參考:

http://www.innomysql.com/article/24297.html

2. MySQL升級

這里演示從5.6升級到5.7

2.1 停止數(shù)據(jù)庫

[root@lab11g mysql]# /etc/init.d/mysql.server stop
Shutting down MySQL..[確定]

2.2 注意datadir參數(shù),改成真實路徑,生產(chǎn)環(huán)境應(yīng)該是和軟件目錄分離的,所以該步驟不需要

datadir = /usr/local/mysql-5.6.31-linux-glibc2.5-x86_64/data

2.3 unlink mysql并link5.7路徑

[root@lab11g local]# unlink mysql
[root@lab11g local]# ln -s mysql-5.7.13-linux-glibc2.5-x86_64 mysql
[root@lab11g local]# /etc/init.d/mysql.server start
Starting MySQL.............                                [確定]
[root@lab11g local]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> use test
Database changed
mysql> show tables;
Empty set (0.00 sec)

這時候啟動發(fā)現(xiàn)已經(jīng)是5.7了,說明5.6和5.7的二進(jìn)制文件是兼容的,但是error.log里面有很多Warning甚至ERROR, 如下:

2016-07-06T20:35:39.334153+08:00 0 [ERROR] Incorrect definition of table performance_schema.events_waits_current: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
2016-07-06T20:35:39.334202+08:00 0 [ERROR] Incorrect definition of table performance_schema.events_waits_history: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').

2.4 使用mysql_upgrade升級數(shù)據(jù)文件

[root@lab11g data]# mysql_upgrade                   ---- 如果有密碼的話也要mysql_upgrade
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
Upgrading the sys schema.
Checking databases.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.
[root@lab11g data]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |                  ---- 5.7的sys庫
| test               |                  ---- 5.6的test庫
+--------------------+
5 rows in set (0.00 sec)

mysql_upgrade會把所有的包括業(yè)務(wù)表全部重新建一遍,但是只要是innodb都是兼容的,如果數(shù)據(jù)量很大,是沒有必要的。只升級系統(tǒng)表即可,如下:

[root@lab11g data]# mysql_upgrade --help
......
  -s, --upgrade-system-tables 
                      Only upgrade the system tables, do not try to upgrade the
                      data.
......
[root@lab11g data]# mysql_upgrade -s --force                            ---- 我這里已經(jīng)升級過了,所以force
The --upgrade-system-tables option was used, databases won't be touched.
Checking server version.
Running queries to upgrade MySQL server.
The sys schema is already up to date (version 1.5.0).
Upgrade process completed successfully.
Checking if update is needed.

什么時候不需要-s? 比如老版本的業(yè)務(wù)表沒有按照新特性來存,升級會有一些性能的提升。但是提升不會太大,所以說通常來說沒有必要。

一般來說非跨版本升級,有可能有參數(shù)過期,日志里面會有Warning, 如下:

2016-07-06T21:01:54.109662+08:00 0 [Warning] InnoDB: Using innodb_file_format is deprecated and the parameter may be removed in future releases. See http://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html
2016-07-06T21:01:54.109692+08:00 0 [Warning] InnoDB: Using innodb_file_format_max is deprecated and the parameter may be removed in future releases. See http://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html

如果說版本升級后,二進(jìn)制文件不兼容,比如4.0->4.1, 數(shù)據(jù)文件也是不兼容的,需要mysqldump.

2.5 關(guān)于降級

因為使用了-s升級,升級前可以對5.6的系統(tǒng)庫進(jìn)行備份,升級之后降級只要將系統(tǒng)庫覆蓋回來

cp -rf -a mysql/ mysql_old

在實際降級過程中通過覆蓋mysql系統(tǒng)表的方式存在問題,會導(dǎo)致啟動不起來。官方MySQL5.7降級文檔有建議,根據(jù)文檔中建議使用的SQL語句可在mysql5.7的源碼的srcipts/mysql_system_tables_fix_for_downgrade.sql中找到,或者直接運行這個sql腳本。

但是測試后發(fā)現(xiàn),有bug, 可以啟動,但是原來的用戶表,無法訪問。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,002評論 6 542
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,400評論 3 429
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,136評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,714評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 72,452評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,818評論 1 328
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,812評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,997評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,552評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 41,292評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,510評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,035評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,721評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,121評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,429評論 1 294
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,235評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 48,480評論 2 379

推薦閱讀更多精彩內(nèi)容