MySQL5.6.30 升级到MySQL5.7.18

本次升级采用:out of place 逻辑升级方式:

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

升级MySQL检查:
①:现有MySQL数据库是否已经备份
②:业务是否已经停止

1、检查现有环境:
①:检查MySQL状态:
[[email protected] ~]$ ps -ef | grep mysql
mysql     1806     1  0 14:36 ?        00:00:00 /bin/sh /mysql/bin/mysqld_safe --defaults-file=/mysql/my.cnf
mysql     1868  1806  0 14:36 ?        00:00:00 /mysql/bin/mysqld --defaults-file=/mysql/my.cnf --basedir=/mysql --datadir=/mysql/data --plugin-dir=/mysql/lib/plugin --log-error=/mysql/data/db2.err --pid-file=/mysql/data/db2.pid

②:查看现有配置文件
[[email protected] ~]$ vim /mysql/my.cnf

[mysql]
no_auto_rehash
default_character_set     = utf8
socket                    = /mysql/data/mysql.sock

[client]
default_character_set     = utf8

[mysqld]

server_id                 = 1607
port                      = 3306
basedir                   = /mysql/
datadir                   = /mysql/data/
socket                    = /mysql/data/mysql.sock
pid_file                  = /mysql/data/mysql.pid
log_error                 = /mysql/data/mysql_error.log
log_bin                   = /mysql/data/mysql_bin
relay_log                 = /mysql/data/relay_bin
character_set_server      = utf8
collation_server          = utf8_general_ci

innodb_buffer_pool_size   = 8G
innodb_buffer_pool_instances = 8
innodb_log_file_size      = 1G
innodb_log_files_in_group = 3
innodb_log_buffer_size    = 24M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table     = 1
innodb_flush_method       = O_DIRECT
innodb_io_capacity        = 200
innodb_io_capacity_max    = 600
innodb_thread_concurrency = 0
innodb_autoinc_lock_mode  = 2
innodb_lock_wait_timeout  = 60
innodb_read_io_threads    = 4
innodb_write_io_threads   = 4
innodb_max_dirty_pages_pct = 80
innodb_autoextend_increment = 512
innodb_checksum_algorithm = NONE
innodb_doublewrite        = 0
innodb_use_native_aio     = 1
innodb_open_files         = 8192

sync_binlog               = 1
sync_relay_log            = 1
relay_log_info_repository = TABLE
master_info_repository    = TABLE
expire_logs_days          = 10
binlog_format             = ROW
transaction-isolation     = READ-COMMITTED
concurrent_insert         = 2
skip_slave_start          = TRUE

back_log                  = 2000
thread_stack              = 256k
thread_cache_size         = 256
key_buffer_size           = 256M
tmp_table_size            = 64M
read_buffer_size          = 2M
read_rnd_buffer_size      = 8M
sort_buffer_size          = 2M
join_buffer_size          = 2M
query_cache_size          = 0
query_cache_type          = 0
max_heap_table_size       = 64M
binlog_cache_size         = 2M
table_open_cache          = 8192
max_allowed_packet        = 64M
bulk_insert_buffer_size   = 64M

max_connect_errors        = 100000
max_connections           = 500
connect_timeout           = 300
wait_timeout              = 86400
interactive_timeout       = 86400
lower_case_table_names    = 1
open_files_limit          = 20480
skip_name_resolve
skip_external_locking
explicit_defaults_for_timestamp = TRUE
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

③:检查现有MySQL的版本信息:
[[email protected] ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.30 Source distribution

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

mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.6.30, for Linux (x86_64) using  EditLine wrapper

Connection id:          6
Current database:
Current user:           [email protected]
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ‘‘
Using delimiter:        ;
Server version:         5.6.30 Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /tmp/mysql.sock
Uptime:                 5 min 32 sec

Threads: 1  Questions: 18  Slow queries: 0  Opens: 67  Flush tables: 1  Open tables: 60  Queries per second avg: 0.054
--------------

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.30    |
+-----------+
1 row in set (0.01 sec)

mysql>

④:关闭数据库:
[[email protected] ~]$ mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0"
Enter password:
[[email protected] ~]$ mysql -u root -p --execute="show global variables like ‘innodb_fast_shutdown‘"
Enter password:
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| innodb_fast_shutdown | 0     |
+----------------------+-------+
[[email protected] ~]$ mysqladmin -uroot -p shutdown
Enter password:

注意:innodb_fast_shutdown参数解释:
关闭:innodb_fast_shutdown=
0 :完成所有的full purge和merge insert buffer操作(如:做InnoDB plugin升级时)
1 :默认,不需要完成上述操作,但会刷新缓冲池中的脏页
2 :不完成上述两个操作,而是将日志写入日志文件,下次启动时,会执行恢复操作recovery
没有正常地关闭数据库(如:kill命令)/innodb_fast_shutdown=2时,需要进行恢复操作。

2、下载mysql5.7.18,并且解压到新目录
mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz     (这个软件包解压后就可以用,不用安装)
[[email protected] ~]$ tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz   (把软件直接解压到/home/mysql)
[[email protected] ~]$ mv mysql-5.7.18-linux-glibc2.5-x86_64/    mysql5718   (mysql5718这个就是新的软件目录)

3、修改配置文件:my.cnf
[[email protected] mysql5718]$ cp /mysql/my.cnf ./
[[email protected] mysql5718]$ vim my.cnf
basedir                   = /home/mysql/mysql5718/     -----只需要修改这一行就可以,指向新目录

4、使用新软件启动MySQL数据库:
[[email protected] mysql5718]$ /home/mysql/mysql5718/bin/mysqld_safe --defaults-file=/home/mysql/mysql5718/my.cnf --socket=/mysql/data/mysql.sock &

5、升级MySQL:
[[email protected] mysql5718]$ /home/mysql/mysql5718/bin/mysql_upgrade -uroot -p --socket=/mysql/data/mysql.sock
Enter password:
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
Upgrading the sys schema.
Checking databases.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.

出现上述信息,就表明MySQL升级完成了;

6、升级完成后,重启数据库
[[email protected] mysql5718]$ /home/mysql/mysql5718/bin/mysqladmin shutdown -u root -p
[[email protected] mysql5718]$ /home/mysql/mysql5718/bin/mysqld_safe --defaults-file=/home/mysql/mysql5718/my.cnf --socket=/mysql/data/mysql.sock &

7、登录数据库检查升级状态:
[[email protected] bin]$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
有时候我们登录MySQL的时候会出现上面的错误,可是我们已经在配置文件指定了mysql.sock的目录呀,为什么还去找别的目录呢,解决方法有两种:
第一在my.cnf配置文件添加下面的信息:(有时候不管用,比如我们上面的配置文件已经添加了可是还是报错)
[mysql]
socket                    = /mysql/data/mysql.sock

第二种:我们做个软连接到tmp下就可以了:
[[email protected] bin]$ ln -s /mysql/data/mysql.sock /tmp/mysql.sock
做完软连接后,我们再等了数据库就OK了:
[[email protected] bin]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> \s
--------------
mysql  Ver 14.14 Distrib 5.6.30, for Linux (x86_64) using  EditLine wrapper

Connection id:          3
Current database:
Current user:           [email protected]
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ‘‘
Using delimiter:        ;
Server version:         5.7.18-log MySQL Community Server (GPL)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /tmp/mysql.sock
Uptime:                 4 min 16 sec

Threads: 1  Questions: 6  Slow queries: 0  Opens: 110  Flush tables: 1  Open tables: 25  Queries per second avg: 0.023
--------------

mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.18-log |
+------------+
1 row in set (0.39 sec)

mysql>

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

知识扩展:
关闭:innodb_fast_shutdown=

0 :完成所有的full purge和merge insert buffer操作(如:做InnoDB plugin升级时)
1 :默认,不需要完成上述操作,但会刷新缓冲池中的脏页
2 :不完成上述两个操作,而是将日志写入日志文件,下次启动时,会执行恢复操作recovery
    没有正常地关闭数据库(如:kill命令)/innodb_fast_shutdown=2时,需要进行恢复操作。

恢复:innodb_force_recovery=

0 :默认,但需要恢复时执行所有恢复操作
1 :忽略检查到的corrupt页
2 :阻止主线程的运行,如主线程需要执行full purge操作,会导致crash
3 :不执行事务回滚操作
4 :不执行插入缓冲的合并操作
5 :不查看撤销日志undo log,InnoDB存储引擎会将所有未提交的事务视为已提交
6 :不执行前滚的操作

时间: 2024-10-01 04:43:30

MySQL5.6.30 升级到MySQL5.7.18的相关文章

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

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

CentOS6.5 安装mysql5.6.30

1.下载解压由于系统会自带mysql5.1版本的数据库,需要卸载.[[email protected] src]# yum remove -y mysql-libs[[email protected] src]# yum remove -y mysql[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.30.tar.gz[[email protected] src]# tar -zxvf

centos6.5下安装mysql5.6.30

1.解压mysql tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  -C /usr/local mv mysql-5.6.30-linux-glibc2.5-x86_64 mysql-5.6.30 2.添加用户与组 groupadd mysql useradd -g mysql mysql  -s /sbin/nologin  chown -R mysql:mysql mysql-5.6.30 3.安装数据库 mkdir /usr/local

centos6.5下的mysql5.6.30安装

http://www.cnblogs.com/fujinzhou/p/5750442.html centos6.5下的mysql5.6.30安装 1.解压mysql tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  -C /usr/local mv mysql-5.6.30-linux-glibc2.5-x86_64 mysql-5.6.30 2.添加用户与组 groupadd mysql useradd -g mysql mysql  -s

Linux下源码安装MySQL5.6.30

环境简介 linux :cenos 6.5 mysql版本:mySQL5.6.30 Mysql5.6.30安装与mySQL5.1安装还是有一些区别了,需要使用cmake进行安装信息的配置.据说Mysql从5.5以后安装都需要cmake. Mysql5.6.30里面没有configure,没法通过./configure 进行安装配置,需要自己去生成配置信息 MySQL5.6.30安装 前期准备 创建mysql用户与mysql组 创建组:groupadd mysql 创建用户:useradd -r

ubuntu12.04安装mysql5.6.30 及遇到的问题解决

系统环境:ubuntu12.04(32bit) 需要安装的mysql版本是5.6.30 在安装5.6.30之前,找到网上的资料,安装了5.5的版本,后来,我将5.5的卸载了,再安装5.6的. 首先,去Mysql官网找自己系统对应的版本,我是想通过deb版本安装的. $ cd  /usr/local/src    #一般下载的文件都放到这里 $ sudo wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-server_5.6.30-1d

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

Centos7.1 for MySQL5.6.30源码安装

预备工作: OS:Centos7.1 DATABASE: mysql-5.6.30.tar.gz 1. 创建mysql帐号 创建用户和用户组   [[email protected] ~]# groupadd mysql       [[email protected] ~]# useradd -g mysql mysql   [[email protected] ~]# passwd mysql 2.验证安装包 先验证之前是否安装过mysql,若存在mysql相关包,则rpm -e逐个删除(建