Welcome 微信登录

首页 / 数据库 / MySQL / MySQL升级 参考分享

MySQL的升级相对来说还是比较简单的。它支持两种方式的升级:原地升级(In-place Upgrade)关闭数据库,替换旧的二进制文件,重启数据库,执行mysql_upgrade逻辑升级(Logical Upgrade)用mysqldump导出数据,安装新的数据库版本,将数据导入到新的数据库中,执行mysql_upgrade但是MySQL版本众多,不仅有各种大版本,譬如5.1,5.5,5.6,5.7,同一个大版本中也会有各种小版本。那么官方支持怎么的升级路径呢?1. 同一个大版本中的小版本升级,譬如5.6.25到5.6.31。2. 跨版本升级,但只支持跨一个版本升级,譬如5.5到5.6,5.6到5.7。3. 不支持跨版本的直接升级,譬如直接从5.1到5.6,可以先从5.1升级到5.5,再从5.5升级到5.6。以上均是指MySQL的GA版本,从非GA版本到GA版本的升级并不支持,譬如5.6.9到5.6.10,因为前者并不是一个GA版本。关于版本信息,可参考官方说明http://downloads.mysql.com/archives/community/下面演示一下原地升级待升级版本MySQL 5.5.30目标版本MySQL 5.6.32 设置参数mysql> set global innodb_fast_shutdown=0;Query OK, 0 rows affected (0.00 sec)innodb_fast_shutdown参数有三个值0: 在数据库关闭的时候,会执行purge操作和change buffer合并,也称为“show shutdown”1: 默认值,在数据库关闭的时候,会跳过purge操作和change buffer合并,也称为“fast shutdown”2: 在数据库关闭的时候,只是flush log,然后执行关闭操作。在恢复的时候可能需要较长时间的crash recovery彻底关闭数据库# ./bin/mysqladmin shutdown -uroot -p123456 --socket /data/mysql.sock更新MySQL二进制文件在这里,我直接使用新的二进制压缩包使用新的MySQL启动此时datadir指向原来的数据目录# ./bin/mysqld_safe--defaults-file=/usr/test/mysql-5.6.32-linux-glibc2.5-x86_64/my.cnf --user=mysql --ledir=/usr/test/mysql-5.6.32-linux-glibc2.5-x86_64/bin&其中,配置文件中的内容如下[mysqld]basedir = /usr/test/mysql-5.6.32-linux-glibc2.5-x86_64datadir = /dataport = 3310socket = /data/mysql.sock主要是指定了datadir执行mysql_upgrade# ./bin/mysql_upgrade -uroot -p123456 --socket=/data/mysql.sockWarning: Using a password on the command line interface can be insecure.Looking for "mysql" as: ./bin/mysqlLooking for "mysqlcheck" as: ./bin/mysqlcheckRunning "mysqlcheck" with connection arguments: "--socket=/data/mysql.sock" Warning: Using a password on the command line interface can be insecure.Running "mysqlcheck" with connection arguments: "--socket=/data/mysql.sock" Warning: Using a password on the command line interface can be insecure.mysql.columns_priv OKmysql.db OKmysql.eventOKmysql.func OKmysql.general_logOKmysql.help_categoryOKmysql.help_keyword OKmysql.help_relationOKmysql.help_topic OKmysql.host OKmysql.ndb_binlog_index OKmysql.plugin OKmysql.proc OKmysql.procs_priv OKmysql.proxies_priv OKmysql.serversOKmysql.slow_log OKmysql.tables_privOKmysql.time_zoneOKmysql.time_zone_leap_secondOKmysql.time_zone_name OKmysql.time_zone_transition OKmysql.time_zone_transition_typeOKmysql.user OKRunning "mysql_fix_privilege_tables"...Warning: Using a password on the command line interface can be insecure.Running "mysqlcheck" with connection arguments: "--socket=/data/mysql.sock" Warning: Using a password on the command line interface can be insecure.Running "mysqlcheck" with connection arguments: "--socket=/data/mysql.sock" Warning: Using a password on the command line interface can be insecure.test.testOKOK 关于mysql_upgrade的作用,官方文档说明如下:mysql_upgrade examines all tables in all databases for incompatibilities with the current version of MySQL Server. mysql_upgrade also upgrades the system tables so that you can take advantage of new privileges or capabilities that might have been added.If mysql_upgrade finds that a table has a possible incompatibility, it performs a table check and, if problems are found, attempts a table repair. 主要是升级系统表和修复不兼容的表。参考1. http://dev.mysql.com/doc/refman/5.6/en/upgrading.html本文永久更新链接地址