当前位置: 首页 >数据库 > 【转载】MySQL版本升级之5.6到5.7

【转载】MySQL版本升级之5.6到5.7

文一

两种升级方式

  • In-Place Upgrade: Involves shutting down the old MySQL version, replacing the old MySQL binaries or packages with the new ones, restarting MySQL on the existing data directory, and running mysql_upgrade.

  • Logical Upgrade: Involves exporting existing data from the old MySQL version using mysqldump, installing the new MySQL version, loading the dump file into the new MySQL version, and running mysql_upgrade.

 

 

 升级实践(采用in-place方式)

【转载】MySQL版本升级之5.6到5.7 _ JavaClub全栈架构师技术笔记
#关闭快速关闭服务选项,防止关闭服务后有脏页未刷进磁盘,升级后表格式变化无法进行recoverymysql -u root -p123456 -S /tmp/mysql_3306.sock  -e "SET GLOBAL innodb_fast_shutdown=0"#关闭MySQL服务mysqld_multi --defaults-file=/etc/3306.cnf --password='123456' stop 3306#冷拷贝到部署MySQL5.7的环境#启动服务mysqld_multi --defaults-file=/etc/3306.cnf --password='123456' start 3306#更改配置文件,解决版本不兼容的参数配置关注点为sql_mode、并行复制#使用mysqld_upgrade 检查并修改和MySQL5.7结构不一致的地方mysql_upgrade -uroot -p'123456' -S /tmp/mysql_3306.sock 
#重启服务,加载变更的数据结构
【转载】MySQL版本升级之5.6到5.7 _ JavaClub全栈架构师技术笔记

注意点

mysq_upgrade 不会更改help表的内容,需要手动升级,sql文件存储路径在share或 share/mysql目录下

mysql -uroot -S /tmp/mysql_3306.sock <fill_help_tables.sql 

 

 

文二

MySQL升级的两种方式:
in-place upgrade:
适合小版本的升级。
即 关闭当前的MySQL,替换当前的二进制文件或包,在现有的数据目录上重启MySQL,并运行mysql_upgrade.
特点:不改变数据文件,升级速度快;但,不可以跨操作系统,不可以跨大版本(5.5—>5.7).
logical upgrade:
适合不同操作系统的MySQL升级,大版本之间的升级。
即:使用mysqldump 或 mydumper 导入导出数据,实现版本的升级。
特点:可以跨操作系统,跨大版本;但,升级速度慢,容易出现乱码等问题。
升级前的准备:
提前做好备份。
了解新版本变更的信息(哪些不再兼容,不再支持哪些功能)
在官方网站的general information—>what is new in mysql 5.7

升级的注意事项:
确认新版本是否有重大变更
注意 SQL mode 的变化
比如:在MySQL5.7中发生了SQL mode的变化,对不再支持的SQL mode,部分SQL会跑不通,此时可以清空SQL mode,跑完之后在设置SQL mode。
升级成功后,确认业务SQL是否可以跑通
程序层是否都正常
有时原使用的程序语言部分内容不被支持新版本数据库。比如,有一次在5.1时用的是PHP4.0,但升级到5.6,PHP的某些函数不被支持。
在升级完成之后,一定要在测试时使用和线上版本相同的程序,测试是否存在问题。
存储引擎的变化
比如:在未来的5.8版本,不再支持myisam 引擎。
注意字符集的乱码问题
接下来是,使用in-place upgrade方式,将MySQL5.6升级到MySQL5.7。

In-place upgrade 升级MySQL
环境:
5.6.15 —>5.7.20

升级前的准备:
备份+留意新版本的变更内容
升级操作:
1、对5.7的软件包,下载,解压

# tar -xzvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

# ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql5.7

2、关闭当前MySQL(5.6)

# mysql -u root -p -S /data/mysql3308/mysql3308.sock --execute="SET GLOBAL innodb_fast_shutdown=0"

# mysqladmin -u root -p -S /data/mysql3308/mysql3308.sock shutdown

3、替换二进制文件(5.7 替换 5.6)

# cd /usr/local

# mv mysql mysql5.6

# mv mysql5.7 mysql

4、使用现有的数据目录启动MySQL

# mysqld_safe --user=mysql --socket=/data/mysql3308/mysql3308.sock -p --skip-grant-tables --datadir=/data/mysql3308/data

5、检查所有表是否与当前版本兼容,并更新系统库

# mysql_upgrade -uroot -p -S /data/mysql3308/mysql3308.sock

注:mysql_upgrade的作用是检查所有库的所有表是否与当前的新版本兼容,并更新系统库。
6、重启,确保对系统表所做的变更得以生效

# mysqld --defaults-file=/data/mysql3308/my3308.cnf &

# mysql -uroot -p -S /data/mysql3308/mysql3308.sock
至此,升级完成。
---------------------
作者:Joker_Ye
来源:CSDN
原文:https://blog.csdn.net/hj7jay/article/details/78809574
版权声明:本文为博主原创文章,转载请附上博文链接!

 

 

 

 

 

 

 

 

https://dev.mysql.com/doc/refman/5.7/en/upgrade-binary-package.html

 

2.11.4 Upgrading MySQL Binary or Package-based Installations on Unix/Linux

This section describes how to upgrade MySQL binary and package-based installations on Unix/Linux. In-place and logical upgrade methods are described.

In-Place Upgrade

An in-place upgrade involves shutting down the old MySQL server, replacing the old MySQL binaries or packages with the new ones, restarting MySQL on the existing data directory, and upgrading any remaining parts of the existing installation that require upgrading.

Note

If you upgrade an installation originally produced by installing multiple RPM packages, upgrade all the packages, not just some. For example, if you previously installed the server and client RPMs, do not upgrade just the server RPM.

For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysqld_safe is not installed. In such cases, use systemd for server startup and shutdown instead of the methods used in the following instructions. See Section 2.5.10, “Managing MySQL Server with systemd”.

To perform an in-place upgrade:

  1. If you use XA transactions with InnoDB, run XA RECOVER before upgrading to check for uncommitted XA transactions. If results are retued, either commit or rollback the XA transactions by issuing an XA COMMIT or XA ROLLBACK statement.

  2. Configure MySQL to perform a slow shutdown by setting innodb_fast_shutdown to 0. For example:

    mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0"

    With a slow shutdown, InnoDB performs a full purge and change buffer merge before shutting down, which ensures that data files are fully prepared in case of file format differences between releases.

  3. Shut down the old MySQL server. For example:

    mysqladmin -u root -p shutdown
  4. Upgrade the MySQL binary installation or packages. If upgrading a binary installation, unpack the new MySQL binary distribution package. See Obtain and Unpack the Distribution. For package-based installations, install the new packages.

  5. Start the MySQL 5.7 server, using the existing data directory. For example:

    mysqld_safe --user=mysql --datadir=/path/to/existing-datadir &
  6. Run mysql_upgrade. For example:

    mysql_upgrade -u root -p

    mysql_upgrade examines all tables in all databases for incompatibilities with the current version of MySQL. mysql_upgrade also upgrades the mysql system database so that you can take advantage of new privileges or capabilities.

    Note

    mysql_upgrade does not upgrade the contents of the time zone tables or help tables. For upgrade instructions, see Section 5.1.12, “MySQL Server Time Zone Support”, and Section 5.1.13, “Server-Side Help Support”.

  7. Shut down and restart the MySQL server to ensure that any changes made to the system tables take effect. For example:

    mysqladmin -u root -p shutdownmysqld_safe --user=mysql --datadir=/path/to/existing-datadir &

Logical Upgrade

A logical upgrade involves exporting SQL from the old MySQL instance using a backup or export utility such as mysqldumpor mysqlpump, installing the new MySQL server, and applying the SQL to your new MySQL instance.

Note

For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysqld_safe is not installed. In such cases, use systemd for server startup and shutdown instead of the methods used in the following instructions. See Section 2.5.10, “Managing MySQL Server with systemd”.

To perform a logical upgrade:

  1. Review the information in Section 2.11.1, “Before You Begin”.

  2. Export your existing data from the previous MySQL installation:

    mysqldump -u root -p  --add-drop-table --routines --events --all-databases --force > data-for-upgrade.sql
    Note

    Use the --routines and --events options with mysqldump (as shown above) if your databases include stored programs. The --all-databases option includes all databases in the dump, including the mysql database that holds the system tables.

    Important

    If you have tables that contain generated columns, use the mysqldump utility provided with MySQL 5.7.9 or higher to create your dump files. The mysqldump utility provided in earlier releases uses incorrect syntax for generated column definitions (Bug #20769542). You can use theINFORMATION_SCHEMA.COLUMNS table to identify tables with generated columns.

  3. Shut down the old MySQL server. For example:

    mysqladmin -u root -p shutdown
  4. Install MySQL 5.7. For installation instructions, see Chapter 2, Installing and Upgrading MySQL.

  5. Initialize a new data directory, as described at Section 2.10.1, “Initializing the Data Directory”. For example:

    mysqld --initialize --datadir=/path/to/5.7-datadir

    Copy the temporary 'root'@'localhost' password displayed to your screen or written to your error log for later use.

  6. Start the MySQL 5.7 server, using the new data directory. For example:

    mysqld_safe --user=mysql --datadir=/path/to/5.7-datadir &
  7. Reset the root password:

    shell> mysql -u root -pEnter password: **** <- enter temporary root password
    mysql> ALTER USER USER() IDENTIFIED BY 'your new password';
  8. Load the previously created dump file into the new MySQL server. For example:

    mysql -u root -p --force < data-for-upgrade.sql
    Note

    It is not recommended to load a dump file when GTIDs are enabled on the server (gtid_mode=ON), if your dump file includes system tables. mysqldump issues DML instructions for the system tables which use the non-transactional MyISAM storage engine, and this combination is not permitted when GTIDs are enabled. Also be aware that loading a dump file from a server with GTIDs enabled, into another server with GTIDs enabled, causes different transaction identifiers to be generated.

  9. Run mysql_upgrade. For example:

    mysql_upgrade -u root -p

    mysql_upgrade examines all tables in all databases for incompatibilities with the current version of MySQL. mysql_upgrade also upgrades the mysql system database so that you can take advantage of new privileges or capabilities.

    Note

    mysql_upgrade does not upgrade the contents of the time zone tables or help tables. For upgrade instructions, see Section 5.1.12, “MySQL Server Time Zone Support”, and Section 5.1.13, “Server-Side Help Support”.

  10. Shut down and restart the MySQL server to ensure that any changes made to the system tables take effect. For example:

     
    mysqladmin -u root -p shutdownmysqld_safe --user=mysql --datadir=/path/to/5.7-datadir &

 

作者:EngineTang
来源链接:https://www.cnblogs.com/infaaf/p/10572736.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/118915.html

标签:MySQL升级
分享给朋友:

“【转载】MySQL版本升级之5.6到5.7” 的相关文章

全面解析Redis 2022年05月13日 10:22:02
Mybatis中的${}和#{}区别 2022年05月17日 21:41:44
数据库之事务及事务的 ACID 性质 2022年05月21日 11:37:16
mysql查询最新的一条记录 2022年06月06日 16:04:12
Mysql 查询结果赋值到变量 2022年06月07日 12:35:42
mysql 查询表 所有字段 2022年06月09日 20:38:57
MYSQL根据日期查询 2022年06月11日 21:03:52
mysql 查询所有下级 2022年06月12日 13:42:12
关于mysql数据库连接异常处理 2022年06月12日 19:21:20