1. 程式人生 > >MySQL 5.6升級至MySQL 5.7--------版本升級最佳實戰

MySQL 5.6升級至MySQL 5.7--------版本升級最佳實戰

mysql dba

1. 背景

MySQL 5.7是當前MySQL最新版本,與MySQL 5.6版本相比,有如下特征

  * 性能和可擴展性:改進 InnoDB 的可擴展性和臨時表的性能,從而實現更快的網絡和大數據加載等操作。

* JSON支持:使用 MySQL 的 JSON 功能,你可以結合 NoSQL 的靈活和關系數據庫的強大。

* 改進復制 以提高可用性的性能。包括多源復制,多從線程增強,在線 GTIDs,和增強的半同步復制。

* 性能模式 提供更好的視角。我們增加了許多新的監控功能,以減少空間和過載,使用新的 SYS 模式顯著提高易用性。

* 安全: 我們貫徹“安全第一”的要求,許多 MySQL 5.7 新功能幫助用戶保證他們數據庫的安全。

* 優化: 重寫了大部分解析器,優化器和成本模型。這提高了可維護性,可擴展性和性能。

* GIS: MySQL 5.7 全新的功能,包括 InnoDB 空間索引,使用 Boost.Geometry,同時提高完整性和標準符合性。


2. 當前運行的MySQL 5.6環境

* MySQL當前版本

[[email protected] ~]# /usr/local/mysql/bin/mysql  -p123456
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 2
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> select version();
+-----------+
| version() |
+-----------+
| 5.6.36    |
+-----------+
1 row in set (0.05 sec)

mysql>


* MySQL所在目錄

[[email protected] ~]# ll /usr/local/mysql-5.6.36-linux-glibc2.5-x86_64
total 72
drwxr-xr-x  2 mysql mysql  4096 Jun 24 04:05 bin
-rw-r--r--  1 mysql mysql 17987 Mar 18 14:43 COPYING
drwxr-xr-x  3 mysql mysql  4096 Jun 24 04:05 data
drwxr-xr-x  2 mysql mysql  4096 Jun 24 04:05 docs
drwxr-xr-x  3 mysql mysql  4096 Jun 24 04:05 include
drwxr-xr-x  3 mysql mysql  4096 Jun 24 04:06 lib
drwxr-xr-x  4 mysql mysql  4096 Jun 24 04:05 man
-rw-r--r--  1 root  root    943 Jun 24 04:08 my.cnf
drwxr-xr-x 10 mysql mysql  4096 Jun 24 04:05 mysql-test
-rw-r--r--  1 mysql mysql  2496 Mar 18 14:43 README
drwxr-xr-x  2 mysql mysql  4096 Jun 24 04:05 scripts
drwxr-xr-x 28 mysql mysql  4096 Jun 24 04:05 share
drwxr-xr-x  4 mysql mysql  4096 Jun 24 04:06 sql-bench
drwxr-xr-x  2 mysql mysql  4096 Jun 24 04:05 support-files


* MySQL 數據所在目錄

[[email protected] ~]# ll /data/mysql_data
total 110616
-rw-rw---- 1 mysql mysql       56 Jun 24 04:10 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Jun 24 04:10 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Jun 24 04:10 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jun 24 04:08 ib_logfile1
drwx------ 2 mysql mysql     4096 Jun 24 04:08 mysql
-rw-rw---- 1 mysql mysql     1771 Jun 24 04:10 MySQL.err
-rw-rw---- 1 mysql mysql        6 Jun 24 04:10 MySQL.pid
drwx------ 2 mysql mysql     4096 Jun 24 04:08 performance_schema
drwx------ 2 mysql mysql     4096 Jun 24 04:08 test


* MySQL 啟動腳本basedir與datadir設置

[[email protected] ~]# grep -E ‘^basedir=|^datadir=‘ /etc/init.d/mysqld 
basedir=/usr/local/mysql
datadir=/data/mysql_data

 

3. 升級

* 正常停止數據庫

[[email protected] mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!


* 下載 MySQL 5.7 最新版 [ 推薦從MySQL官方下載 ]

[[email protected] ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


* 解壓到指定目錄

[[email protected] ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/


* 刪除原有的軟鏈接

[[email protected] ~]# unlink /usr/local/mysql


* 新建軟鏈接指向 MySQL 5.7目錄

[[email protected] ~]# ln -s  /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql

* 通過腳本啟動MySQL

[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL..... SUCCESS!


* 利用MySQL 5.7包中的mysql_upgrade 升級MySQL數據中的系統表 -p指定密碼

[[email protected] ~]# /usr/local/mysql/bin/mysql_upgrade -s -p123456
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
The --upgrade-system-tables option was used, databases won‘t be touched.
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Upgrading the sys schema.
Upgrade process completed successfully.
Checking if update is needed.


* 連接MySQL服務查看版本

[[email protected] ~]# /usr/local/mysql/bin/mysql -p123456
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 5
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> select version();
+-----------+
| version() |
+-----------+
| 5.7.18    |
+-----------+
1 row in set (0.00 sec)



4. 總結


以需求驅動技術,技術本身沒有優略之分,只有業務之分。

本文出自 “sea” 博客,請務必保留此出處http://lisea.blog.51cto.com/5491873/1941616

MySQL 5.6升級至MySQL 5.7--------版本升級最佳實戰