mysql数据库管理-MySQL 5.6升级至MySQL 5.7----版本升级最佳实战

MySQL 5.6升级至MySQL 5.7--------版本升级最佳实战

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当前版本

[root@MySQL ~]# /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所在目录

[root@MySQL ~]# 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 数据所在目录

[root@MySQL ~]# 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设置

[root@MySQL ~]# grep -E '^basedir=|^datadir=' /etc/init.d/mysqld 
basedir=/usr/local/mysql
datadir=/data/mysql_data

3. 升级

   * 正常停止数据库

11:07:  [(none)]> show variables like '%sql_mode%';
+---------------+-------------------------------------------------------------------------------------
----------------------------------+
| Variable_name | Value
                                  |
+---------------+-------------------------------------------------------------------------------------
----------------------------------+
| sql_mode      | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISI
ON_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+---------------+-------------------------------------------------------------------------------------
----------------------------------+
1 row in set, 1 warning (0.01 sec)
11:07:  [(none)]> show variables like '%innodb_fast_shutdown%';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| innodb_fast_shutdown | 1     |
+----------------------+-------+
1 row in set, 1 warning (0.01 sec)


11:08:  [(none)]> set global innodb_fast_shutdown =0;
Query OK, 0 rows affected (0.00 sec)

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

* 在my.cnf中添加 skip_grant_table参数

在my.cnf中添加skip_grant_tables参数,确保在执行升级过程中不加载系统字典库启动mysql。

下载 MySQL 5.7 最新版 [ 推荐从MySQL官方下载 ]

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

 * 解压到指定目录

[root@MySQL ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

  * 删除原有的软链接

[root@MySQL ~]# unlink /usr/local/mysql

 * 新建软链接指向 MySQL 5.7目录

[root@MySQL ~]# ln -s  /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql 

ln -s 存在的文件  不存在的文件 

   * 通过脚本启动MySQL

将新版本的mysqld脚本拷贝到/etc/init.d/中
cp $BASEDIR/support_files/mysqld.servce /etc/init.d/mysqld
[root@MySQL ~]# /etc/init.d/mysqld start
Starting MySQL..... SUCCESS!

 * 利用MySQL 5.7包中的mysql_upgrade 升级MySQL数据中的系统表 -p指定密码

--mysql 8.0.x开始已经摒弃mysql_upgrade工具,直接聚合到mysqld脚本中。

[root@MySQL ~]# /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服务查看版本

[root@MySQL ~]# /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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值