MySQL5.6.26升级到MySQL5.7.9实战方案【转】

MySQL5.6.26升级到MySQL5.7.9实战方案

转自

MySQL5.6.26升级到MySQL5.7.9实战方案 - 其他网络技术 - 红黑联盟
http://www.2cto.com/net/201512/453682.html

前言

某大公司升级方案,由于公司经常安全扫描,每个版本都有自身的BUG,为了安全到一定时间都会升级到新的版本。本案例采用单机环境升级方案,在单机中搭建主从方案。

1.单机环境

IP:172.16.0.111

系统:SUSE 11

MySQL旧版本:5.6.26

MySQL新版本:5.7.9

2.升级前准备

注意:升级之前查看磁盘空间充足,能在本机搭建从库。

3.安装新版本

旧版本目录

软件目录: /app/mysql5.6/

数据目录:/data/mysql3306/

配置文件:/app/mysql5.6/my.cnf

[client]

socket=/app/mysql5.6/mysql.sock

default-character-set=utf8

#innodb_buffer_pool_size

port=3306

[mysql]

prompt=\\[email protected]\\d \\r:\\m:\\s>

no-auto-rehash

[mysqld_safe]

pid-file=/app/mysql5.6/mysqld.pid

[mysqld]

socket=/app/mysql5.6/mysql.sock

port=3306

character-set-server=utf8

transaction-isolation=READ-COMMITTED

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp=TRUE

lower_case_table_names=1

local-infile=1

skip-name-resolve

table_definition_cache=500

table_open_cache=500

max_connections=1024

max_user_connections=1000

max_connect_errors=65536

max_allowed_packet=16M

query_cache_type=0

basedir=/app/mysql5.6

datadir=/data/mysql3306

slow_query_log=1

long_query_time=1

log-queries-not-using-indexes

#############

event_scheduler=ON

#innodb_buffer_pool_size=20G

innodb_flush_log_at_trx_commit=2

innodb_strict_mode=1

innodb_flush_method=O_DIRECT

innodb_log_files_in_group=3

innodb_file_per_table

log-bin=mysql-bin

binlog-format=ROW

server_id=111

log-slave-updates=1

skip-slave-start

#read_only=1

expire_logs_days=7

sync_binlog=1

新版本目录

软件目录:/app/mysql5.7/

数据目录:/data/mysqldata/

配置文件:/app/mysql5.7/my.cnf

3.1.解压文件

mysql01:~# tar zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

3.2.移动解压文件

mysql01:~ # mvmysql-5.7.9-linux-glibc2.5-x86_64 /app/mysql5.7

mysql01:~ # chown -R mysql:app/app/mysql5.7

3.3.创建数据目录

mysql01:~ # mkdir /data/mysqldata

mysql01:~ # chown -R mysql:app/data/mysqldata

3.4.初始化数据

注意:初始化和之前版本不一样了,初始化时有初始化密码的

mysql01:/data/mysqldata# /app/mysql5.7/bin/mysqld--initialize --user=mysql --basedir=/app/mysql5.7--datadir=/data/mysqldata

2015-12-03T23:34:12.688857Z0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see documentation for moredetails).

2015-12-03T23:34:12.927838Z0 [Warning] InnoDB: New log files created, LSN=45790

2015-12-03T23:34:12.968656Z0 [Warning] InnoDB: Creating foreign key constraint system tables.

2015-12-03T23:34:13.025810Z0 [Warning] No existing UUID has been found, so we assume that this is thefirst time that this server has been started. Generating a new UUID:5c20785f-9a16-11e5-a525-000c294cec8f.

2015-12-03T23:34:13.027457Z0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘cannot be opened.

2015-12-03T23:34:13.028709Z1 [Note] A temporary password is generated for [email protected]: O-FxRJjl_1Yi #初始化密码

3.5.修改配置文件

mysql01:~ # cp /app/mysql5.6/my.cnf /app/mysql5.7/my.cnf

mysql01:/data/mysqldata # vi /app/mysql5.7/my.cnf

[client]

socket=/app/mysql5.7/mysql.sock

default-character-set=utf8

port=3307

[mysql]

prompt=\\[email protected]\\d \\r:\\m:\\s>

no-auto-rehash

[mysqld_safe]

pid-file=/app/mysql5.7/mysqld.pid

[mysqld]

socket=/app/mysql5.7/mysql.sock

port=3307

character-set-server=utf8

transaction-isolation=READ-COMMITTED

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp=TRUE

lower_case_table_names=1

local-infile=1

skip-name-resolve

table_definition_cache=500

table_open_cache=500

max_connections=1024

max_user_connections=1000

max_connect_errors=65536

max_allowed_packet=16M

query_cache_type=0

basedir=/app/mysql5.7

datadir=/data/mysqldata

slow_query_log=1

long_query_time=1

log-queries-not-using-indexes

###################

#############

event_scheduler=ON

#innodb_buffer_pool_size=20G

innodb_flush_log_at_trx_commit=2

innodb_strict_mode=1

innodb_flush_method=O_DIRECT

innodb_log_files_in_group=3

innodb_file_per_table

log-bin=mysql-bin

binlog-format=ROW

server_id=112

log-slave-updates=1

skip-slave-start

#read_only=1

expire_logs_days=7

sync_binlog=1

3.6修改启动脚本

mysql01:/data/mysqldata # cp/app/mysql5.7/support-files/mysql.server /etc/init.d/mysql3307

mysql01:/data/mysqldata # vi/etc/init.d/mysql3307

修改之处

basedir=/app/mysql5.7

datadir=/data/mysqldata

mysql01:/data/mysqldata # chmod +x/etc/init.d/mysql3307

启动新版本MYSQL

mysql01:/data/mysqldata # /etc/init.d/mysql3307 start

Starting MySQL..done

进入MYSQL

mysql01:/data/mysqldata #/app/mysql5.7/bin/mysql-uroot -pO-FxRJjl_1Yi -P3307 --socket=/app/mysql5.7/mysql.sock

4.导出与导入数据

导出数据

[email protected] ~ $mysqldump -uroot -p --default-character-set=utf8 --all-databases--single-transaction --routines --triggers --events --master-data=2 --socket=/app/mysql5.6/mysql.sock >mysql20151211.sql

注解:

--all-databases 导出所有数据库

--single-transaction

该选项在导出数据之前提交一个BEGINSQL语句,BEGIN不会阻塞任何应用程序且能保证导出时数据库的一致性状态。它只适用于多版本存储引擎,仅InnoDB。本选项和--lock-tables选项是互斥的,因为LOCKTABLES会使任何挂起的事务隐含提交。要想导出大表的话,应结合使用--quick选项。

--routines,-R

导出存储过程以及自定义函数。

--triggers

导出触发器。该选项默认启用,用--skip-triggers禁用它。

--events,-E

导出事件。

--master-data

该选项将binlog的位置和文件名追加到输出文件中。如果为1,将会输出CHANGEMASTER命令;如果为2,输出的CHANGEMASTER命令前添加注释信息。该选项将打开--lock-all-tables选项,除非--single-transaction也被指定(在这种情况下,全局读锁在开始导出时获得很短的时间;其他内容参考下面的--single-transaction选项)。该选项自动关闭--lock-tables选项。

[email protected] ~ $more mysql20151211.sql

-- MySQL dump 10.13 Distrib 5.6.26, for linux-glibc2.5 (x86_64)

--

-- Host: localhost Database:

-- ------------------------------------------------------

-- Server version 5.6.26-log

/*!40101 [email protected][email protected]@CHARACTER_SET_CLIENT */;

/*!40101 [email protected][email protected]@CHARACTER_SET_RESULTS */;

/*!40101 [email protected][email protected]@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @[email protected]@TIME_ZONE */;

/*!40103 SET TIME_ZONE=‘+00:00‘ */;

/*!40014 [email protected][email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;

/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS,FOREIGN_KEY_CHECKS=0

*/;

/*!40101 SET @[email protected]@SQL_MODE,SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */;

/*!40111 SET @[email protected]@SQL_NOTES,SQL_NOTES=0 */;

--

-- Position to start replication orpoint-in-time recovery from

--

-- CHANGE MASTER TOMASTER_LOG_FILE=‘mysql-bin.000049‘, MASTER_LOG_POS=120;

#主从搭建时需要的

把备份数据导入新版本

[email protected] ~ $/app/mysql5.7/bin/mysql-uroot -pO-FxRJjl_1Yi -P3307 --socket=/app/mysql5.7/mysql.sock < mysql20151211.sql

查看导入成功

[email protected] ~ $/app/mysql5.7/bin/mysql-uroot -pO-FxRJjl_1Yi -P3307 --socket=/app/mysql5.7/mysql.sock

mysql: [Warning] Using a password on thecommand line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.7.9-log MySQL CommunityServer (GPL)

Copyright (c) 2000, 2015, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.

[email protected](none) 07:51:16>show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| dataaudit |

| fanrenjie |

| huizhe |

| mysql |

| performance_schema |

| sys |

| test |

| test02 |

| test08 |

+--------------------+

10 rows in set (0.00 sec)

[email protected](none) 07:51:20>

5.主从搭建

在Master上增加一个用于复制的账号:

[email protected](none) 07:52:47>GRANT REPLICATIONSLAVE ON *.* TO ‘repl‘@‘172.16.0.%‘ IDENTIFIED BY ‘123456‘;

Query OK, 0 rows affected (1.01 sec)

在SLAVE上执行如下命令

[email protected] ~ $/app/mysql5.7/bin/mysql-uroot -pO-FxRJjl_1Yi -P3307 --socket=/app/mysql5.7/mysql.sock

mysql: [Warning] Using a password on thecommand line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.7.9-log MySQL CommunityServer (GPL)

Copyright (c) 2000, 2015, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.

[email protected](none) 07:51:20>CHANGE MASTER TOMASTER_HOST=‘172.16.0.111‘,MASTER_PORT=3306,MASTER_USER=‘repl‘,MASTER_PASSWORD=‘123456‘,MASTER_LOG_FILE=‘mysql-bin.000049‘,MASTER_LOG_POS=120;

#注意MASTER_LOG_FILE=‘mysql-bin.000049‘,MASTER_LOG_POS=120;与备份数据里的要一样,为了保证数据一致性

Query OK, 0 rows affected, 2 warnings (0.01sec)

root@(none) 08:00:17>start slave; #开启主从

Query OK, 0 rows affected (0.00 sec)

[email protected](none) 08:03:42>show slavestatus\G; #查看复制

*************************** 1. row***************************

Slave_IO_State: Waiting formaster to send event

Master_Host: 172.16.0.111

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000049

Read_Master_Log_Pos: 327

Relay_Log_File:mysql01-relay-bin.000002

Relay_Log_Pos: 524

Relay_Master_Log_File: mysql-bin.000049

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 327

Relay_Log_Space: 733

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 111

Master_UUID:279f439b-5d2f-11e5-ad29-000c294cec8f

Master_Info_File: /data/mysqldata/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for moreupdates

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

Replicate_Rewrite_DB:

Channel_Name:

1 row in set (0.00 sec)

ERROR:

No query specified

[email protected](none) 08:03:55>

6.执行mysql_upgrade命令

官方提到执行这命令可以让原数据启用到新版本的特性,注意:GTID复制不要开启

[email protected] ~$/app/mysql5.7/bin/mysql_upgrade -uroot-p123456 -P3307 --socket=/app/mysql5.7/mysql.sock

mysql_upgrade: [Warning] Using a passwordon the command line interface can be insecure.

Checking if update is needed.

Checking server version.

Running queries to upgrade MySQL server.

Checking system database.

mysql.columns_priv OK

mysql.db OK

mysql.engine_cost OK

mysql.event OK

mysql.func OK

mysql.general_log OK

mysql.gtid_executed OK

mysql.help_category OK

mysql.help_keyword OK

mysql.help_relation OK

mysql.help_topic OK

mysql.innodb_index_stats OK

mysql.innodb_table_stats OK

mysql.ndb_binlog_index OK

mysql.plugin OK

mysql.proc OK

mysql.procs_priv OK

mysql.proxies_priv OK

mysql.server_cost OK

mysql.servers OK

mysql.slave_master_info OK

mysql.slave_relay_log_info OK

mysql.slave_worker_info OK

mysql.slow_log OK

mysql.tables_priv OK

mysql.time_zone OK

mysql.time_zone_leap_second OK

mysql.time_zone_name OK

mysql.time_zone_transition OK

mysql.time_zone_transition_type OK

mysql.user OK

The sys schema is already up to date(version 1.5.0).

Found 0 sys functions, but expected 21.Re-installing the sys schema.

Upgrading the sys schema.

Checking databases.

dataaudit.t_dataaudit_amount_7 OK

fanrenjie.hz_admin OK

fanrenjie.hz_advertisement OK

fanrenjie.hz_car OK

fanrenjie.hz_education OK

fanrenjie.hz_entertainment OK

fanrenjie.hz_food OK

fanrenjie.hz_health OK

fanrenjie.hz_house OK

fanrenjie.hz_it OK

fanrenjie.hz_literature OK

fanrenjie.hz_manager_menu OK

fanrenjie.hz_message OK

fanrenjie.hz_news OK

fanrenjie.hz_sports OK

fanrenjie.hz_subclass_menu OK

fanrenjie.hz_travel OK

huizhe.auth_urllink OK

huizhe.auth_user OK

huizhe.data_baoyou OK

huizhe.data_huazhuangpin OK

huizhe.data_muying OK

huizhe.data_nanzhuang OK

huizhe.data_nvzhuang OK

huizhe.data_products OK

huizhe.data_shipin OK

huizhe.data_tour OK

huizhe.data_tuan OK

huizhe.data_xiebao OK

sys.sys_config OK

Upgrade process completed successfully.

Checking if update is needed.

7.升级切换。

把主库停止,把从库停止后,端口修改成3306,因为为了对生产库没有影响。在停止时必须和应用联系。

停止主库

mysql01:/data/mysqldata #/etc/init.d/mysqld stop

Shutting down MySQL....done

停止从库

mysql01:/data/mysqldata #/etc/init.d/mysql3307 stop

Shutting down MySQL....done

修改启动

mysql01:/data/mysqldata # cd /etc/init.d/

mysql01:/etc/init.d # mv mysqld mysqlold

mysql01:/etc/init.d # mv mysql3307 mysqld

修改配置文件

mysql01:/etc/init.d # vi/app/mysql5.7/my.cnf

[client]

….

port=3306

[mysqld]

…………

port=3306

……

最后启动新版本

mysql01:/etc/init.d # /etc/init.d/mysqldstart

Starting MySQL. Done

清除同步

mysql> resetslave all;

Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;

Empty set (0.00 sec)

ERROR:

No query specified

把环境变量修改如下

[email protected] ~ $vi .profile

export MYSQL_HOME=/app/mysql5.7

export MY_BASEDIR_VERSION=/app/mysql5.7

export PATH=/app/mysql5.7/bin:$PATH

export LD_LIBRARY_PATH=/app/mysql5.7/lib

export PS1=‘\[email protected]\H \w \$‘

让环境变量生效

[email protected] ~ $source .profile

注:过几天如果应用一切正常。

最后清理旧版本的数据与软件

时间: 2024-08-25 05:12:38

MySQL5.6.26升级到MySQL5.7.9实战方案【转】的相关文章

mysql5.6.23升级到mysql5.7.9

5.7.9新特性 一.安全性 1.1. 用户表 mysql.user 的 plugin字段不允许为空, 默认值是 mysql_native_password,而不是 mysql_old_password,不再支持旧密码格式; 1.2. 增加密码过期机制,过期后需要修改密码,否则可能会被禁用,或者进入沙箱模式; 1.3. 使用mysqld --initialize 初始化,默认会自动生成随机密码,并且不创建除 [email protected] 外的其他账号,也不创建 test 库; 改成 mys

MySQL5.6.30 升级到MySQL5.7.18

本次升级采用:out of place 逻辑升级方式: 基本步骤:①:停止业务,备份现有数据库(mysqldump方式或者物理备份)②:下载MySQL5.7.18软件包,然后安装到别的目录,③:修改配置my.cnf配置文件,指定basedir为新的软件目录④:启动新版本数据库,然后执行mysql_upgrade -uroot -p 升级数据库:⑤:升级完成,重启数据库⑥:检查升级结果:select version(); 升级MySQL检查:①:现有MySQL数据库是否已经备份②:业务是否已经停止

LAMP——httpd 2.4.20 + mysql-5.6.26 + php-5.6.22编译安装过程

httpd 2.4.20 + mysql-5.6.26 + php-5.6.22编译安装过程: 资源准备 系统:centos6.5 PHP:wget http://docs.php.net/distributions/php-5.6.22.tar.gz MySQL:wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26.tar.gz APACHE:wget http://mirrors.noc.im/apache//httpd/http

Ubuntu15.04下源码安装MySQL5.6.26数据库

解决Ubuntu 15.04版下源码编译安装MySQL5.6.26数据库问题,这里提供依赖包下载,源码安装方法. (1)安装编译源码需要的包 sudoapt-get install make cmake gcc g++ bison libncurses5-dev 依赖包在博客附件里有下载.下面也有说明一些解决方法. 另外的:cmake-2.8.3.tar.gz安装啊.bison_3.0.2.dfsg-2_i386.deb.ncurses-5.9.tar.gz的依赖缺少的话自己可以去下载安装,由于

MySQL5.6.25升级MySQL5.7.15

MySQL5.6升级MySQL5.7 环境介绍 Part1:写在最前 提到MySQL升级,网上文章数之不尽,但大多数为老的版本,诸如5.1升级到5.5.5.5升级到5.6,今天给大家介绍下MySQL5.6升级到MySQL5.7版本的方法和注意事项. Part2:升级方法 升级的方法一般有两类: 1.利用mysqldump来直接导出sql文件,导入到新库中,这种方法是最省事儿的,也是最保险的,缺点的话,也显而易见,大库的mysqldump费时费力. 2.直接替换掉mysql的安装目录和my.cnf

CentOS 6.5 源码安装MySQL5.6.26

1:下载安装cmake (mysql5.5以后是通过cmake来编译的) 2:创建mysql的安装目录及数据库存放目录 #mkdir /usr/mysql                 //安装mysql #mkdir /usr/mysql/data            //存放数据库 3:创建mysql用户及用户组 #groupadd mysql #useradd -g mysql -s /bin/false -M mysql 4:安装mysql tar -zxv -f /root/mys

MySQL5.6.26打开数据库缓存

1.本例使用的MySQL版本是5.6.26 2.配置文件开启缓存参数 配置完成后,重新启动MySQL服务 service mysql restart 3.查看是否生效 query_cache_type=on即为生效,MySQL5.6.26默认是off query_cache_size是缓存空间大小 query_cache_limit表示单个查询缓存数据的上限值,超过此值就不会缓存 4.查看缓存效果 Qcache_hits :缓存命中率 Qcache_inserts:第一次查询增加的计数器 Qca

CentOS7+Mysql-5.2.26+php-5.6.12+Zabbix-2.4.6

因为前面有几篇写过LNMP的安装配置,这里就全部写命令了 1 关闭 selinux cp /etc/selinux/config /etc/selinux/config.bak vim /etc/selinux/config  #SELINUX=disable #SELINUXTYPE=targeted 2 软件包以及软件安装位置 /src  #软件包位置 /usr/local/软件包安装位置 3 下载并安装mysql5.2.26 wget http://cdn.mysql.com/Downlo

mysql-5.6.26 主主复制

环境如下: CentOS6.5_64 MySQL5.6.26 master1:192.168.1.112 master2:192.168.1.114 mysql 安装 这里就忽略了,主要就是一个细心.有时候一个不小心,就会发现安装失败. 配置master1 1.修改my.cnf文件,增加如下内容: [mysqld] server-id =1    #数据库ID log-bin=myslq-bin    #启用二进制日志     binlog-do-db=tudou1    #需要同步的数据库,这