设为首页 收藏本站
查看: 496|回复: 0

[经验分享] MySQL5.6.25升级MySQL5.7.15

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-21 09:10:20 | 显示全部楼层 |阅读模式
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,利用mysql_upgrade 来完成系统表的升级,这种方法需要备份原有的文件,但属于物理拷贝,速度较快。缺点的话,跨版本升级不推荐这么做,比如mysql5.1升级到mysql5.6,mysql5.5升级到mysql5.7等。
本文采用的是第二种方法升级。

Part3:环境
数据库软件目录:/usr/local/mysql
my.cnf位置:/etc/my.cnf
数据库data目录:/data/mysql
慢日志目录:/data/slowlog
准备工作Part1:MySQL5.6.25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[iyunv@HE3 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> select version();
+------------+
| version()  |
+------------+
| 5.6.25-log |
+------------+
1 row in set (0.00 sec)
mysql> use helei;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_helei |
+-----------------+
| helei           |
+-----------------+
1 row in set (0.00 sec)




我这里用的是5.6.25版本作为待升级库,库中已经模拟和创建了数据库helei和表helei,用以之后验证升级。


Part2:备份
备份整体需要备份的是my.cnf、数据库安装目录、还有数据目录。
[iyunv@HE3 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[iyunv@HE3 etc]# cp -rp my.cnf my_56_old.cnf
[iyunv@HE3 ~]# rm -rf /usr/local/mysql
[iyunv@HE3 local]# cp -rp mysql mysql_56_old
[iyunv@HE3 data]# cp -rp mysql/ mysql_56_old
这里我直接采用cp的方式来进行。

Part3:替换
1.替换/etc/my.cnf为mysql5.7的my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
[iyunv@HE3 ~]#vi /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
port=3306
character-set-server=utf8
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
explicit_defaults_for_timestamp=true
lower_case_table_names=1
back_log=103
max_connections=3000
max_connect_errors=100000
table_open_cache=512
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=51
query_cache_size=32M
#query_cache_limit=4M
transaction_isolation=REPEATABLE-READ
tmp_table_size=96M
max_heap_table_size=96M
###***slowqueryparameters
long_query_time=1
slow_query_log = 1
slow_query_log_file=/data/slowlog/slow.log
###***binlogparameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
binlog_format=MIXED
expire_logs_days=7
###***relay-logparameters
#relay-log=/data/3307/relay-bin
#relay-log-info-file=/data/3307/relay-log.info
#master-info-repository=table
#relay-log-info-repository=table
#relay-log-recovery=1
#***MyISAMparameters
key_buffer_size=16M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=1M
#skip-name-resolve
###***master-slavereplicationparameters
server-id=$SERVERID
slave-skip-errors=all
#***Innodbstorageengineparameters
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
#innodb_file_io_threads=8
innodb_thread_concurrency=16
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_log_file_size=512M
innodb_log_files_in_group=2
innodb_max_dirty_pages_pct=75
innodb_buffer_pool_dump_pct=50
innodb_lock_wait_timeout=50
innodb_file_per_table=on
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet=32M
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
[mysqld_safe]
open-files-limit=8192
log-error=/data/mysql/error.log
pid-file=/data/mysql/mysqld.pid




2.解压新版mysql
[iyunv@HE3 ~]# tar xvf mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz
[iyunv@HE3 ~]# mv mysql-5.7.15-linux-glibc2.5-x86_64 /usr/local/mysql
[iyunv@HE3 ~]# chown -R mysql. /usr/local/mysql

3.替换新版mysqld启动脚本
[iyunv@HE3 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp: overwrite `/etc/init.d/mysqld'? y


开始升级Part1:启动
1
2
3
4
5
6
[iyunv@HE3 ~]# /etc/init.d/mysqld start
Starting MySQL..... SUCCESS!
[iyunv@HE3 ~]# ps -ef|grep mysql
root     26467     1  0 20:30 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/HE3.pid
mysql    27197 26467  4 20:30 pts/2    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/error.log --open-files-limit=8192 --pid-file=/data/mysql/HE3.pid --socket=/tmp/mysql.sock --port=3306
root     27235 25656  0 20:31 pts/2    00:00:00 grep mysql




这里虽然启动成功了,但error日志里能捕捉到很多错误信息,因为没有升级字典,诸如:
1
2
3
4
5
2016-10-20T03:30:27.375466Z 0 [ERROR] Native table 'performance_schema'.'events_statements_summary_by_program' has the wrong structure
2016-10-20T03:30:27.375506Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_current' has the wrong structure
2016-10-20T03:30:27.375536Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_history' has the wrong structure
2016-10-20T03:30:27.375568Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_history_long' has the wrong structure
2016-10-20T03:30:27.375598Z 0 [ERROR] Native table 'performance_schema'.'events_transactions_summary_by_thread_by_event_name' has the wrong structure





Part2:系统表升级
1.升级数据字典
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[iyunv@HE3 ~]# /usr/local/mysql/bin/mysql_upgrade -uroot -pMANAGER
mysql_upgrade: [Warning] Using a password on 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
Upgrading the sys schema.
Checking databases.
helei.helei                                        OK
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.




2.重启实例再次检查error日志
[iyunv@HE3 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

3.请保证一些路径的设置和以前的my.cnf一致,如果设置错误,很可能导致启动不了数据库
[ERROR] Could not use /data/slowlog/slow.log for logging
我这里是由于慢日志的位置和老的mysql5.6路径不一致,创建/data/slowlog即可,这里要仔细看报错,然后根据报错来发现和解决问题。


验证结果Part1:输入用户名密码检查结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@HE3 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15-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> select version();
+------------+
| version()  |
+------------+
| 5.7.15-log |
+------------+
1 row in set (0.00 sec)



Part2:验证库和表是否有丢失
1
2
3
4
5
6
7
8
9
10
11
12
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| helei              |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
6 rows in set (0.00 sec)




升级5.7后,我们会发现多了一个sys库,这个库有很多的功能,以后再给大家慢慢介绍~


——总结——

MySQL升级有多种方式,但无论采用何种方式,走要做好备份和回滚的准备,以避免升级失败所带来的损失。由于笔者的水平有限,编写时间也很仓促,文中难免会出现一些错误或者不准确的地方,不妥之处恳请读者批评指正。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-289192-1-1.html 上篇帖子: 《PHP与MySQL程序设计》面向对象的PHP 下篇帖子: 《PHP与MySQL程序设计》第三章 PHP基础
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表