zoukankan      html  css  js  c++  java
  • 【转载】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方式)

    复制代码
    #关闭快速关闭服务选项,防止关闭服务后有脏页未刷进磁盘,升级后表格式变化无法进行recovery
    mysql -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 
    #重启服务,加载变更的数据结构
    复制代码

    注意点

    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 returned, 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 shutdown
      mysqld_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 -p
      Enter 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 shutdown
      mysqld_safe --user=mysql --datadir=/path/to/5.7-datadir &
  • 相关阅读:
    Codeforces 938G(cdq分治+可撤销并查集+线性基)
    codeforces 938F(dp+高维前缀和)
    寒武纪camp Day6
    寒武纪camp Day5
    寒武纪camp Day4
    bzoj4161 (k^2logn求线性递推式)
    loj10003加工生产调度
    loj10002喷水装置
    loj10001种树
    bzoj1023
  • 原文地址:https://www.cnblogs.com/infaaf/p/10572736.html
Copyright © 2011-2022 走看看