开发者社区> 技术小甜> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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状态:
[mysql@db2 ~]$ 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

②:查看现有配置文件
[mysql@db2 ~]$ 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的版本信息:
[mysql@db2 ~]$ 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:           root@localhost
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> 

④:关闭数据库:
[mysql@db2 ~]$ mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0"
Enter password: 
[mysql@db2 ~]$ mysql -u root -p --execute="show global variables like 'innodb_fast_shutdown'"
Enter password: 
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| innodb_fast_shutdown | 0     |
+----------------------+-------+
[mysql@db2 ~]$ 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     (这个软件包解压后就可以用,不用安装)
[mysql@db2 ~]$ tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz   (把软件直接解压到/home/mysql)
[mysql@db2 ~]$ mv mysql-5.7.18-linux-glibc2.5-x86_64/    mysql5718   (mysql5718这个就是新的软件目录)

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

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

5、升级MySQL:
[mysql@db2 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、升级完成后,重启数据库
[mysql@db2 mysql5718]$ /home/mysql/mysql5718/bin/mysqladmin shutdown -u root -p
[mysql@db2 mysql5718]$ /home/mysql/mysql5718/bin/mysqld_safe --defaults-file=/home/mysql/mysql5718/my.cnf --socket=/mysql/data/mysql.sock &

7、登录数据库检查升级状态:
[mysql@db2 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下就可以了:
[mysql@db2 bin]$ ln -s /mysql/data/mysql.sock /tmp/mysql.sock
做完软连接后,我们再等了数据库就OK了:
[mysql@db2 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:           root@localhost
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 :不执行前滚的操作














本文转自一个笨小孩51CTO博客,原文链接: http://blog.51cto.com/fengfeng688/1921636,如需转载请自行联系原作者





版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
[TypeScript]编译配置
自动编译文件,编译文件时,使用 -w 指令后,TS编译器会自动监视文件的变化,并在文件发生变化时对文件进行重新编译。
11 0
mysql升级
演示以及5.5升级到5.6 当前数据库信息 mysql> status; -------------- mysql Ver 14.14 Distrib 5.
798 0
Git 1.9.5.msysgit.1
Git 1.9.5.msysgit.1 发布,现已提供下载:https://github.com/msysgit/git/archive/v1.9.5.msysgit.1.zip。 Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。
1045 0
MSGRID的填充
这是记录的一些填充代码,其实MSGRID就是一个二维表格,主要在控制单元格的高度和宽度上有点技巧,但本人认为MSGRID并不太好用。   下面编写了一个用记录集填充AxMSFlexGrid网格的过程。其中函数RecordCount是我自己编写的求记录集中记录的函数。
836 0
mysql5.6升级5.7(物理方式)
本文的升级方式为物理升级: 直接替换掉mysql的安装目录和修改my.cnf,利用mysql_upgrade来完成系统表的升级,这种方法需要备份原有的文件,属于物理拷贝,速度较快。
1485 0
+关注
10136
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载