当前位置: 首页 >数据库 > Mysql5.7升级至Mysql8过程

Mysql5.7升级至Mysql8过程

 

具体升级过程

 

下面以Linux系统为例,展示下具体升级过程。我的系统是CentOS7.7,原版本是MySQL5.7.23,以In-Place方式直接升级到MySQL8.0.19。

下载解压安装包

官网下载对应版本的tar包,可通过wget下载或者本地下载后上传。

下载地址:
https://downloads.mysql.com/archives/community/
选择mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz

执行以下步骤解压tar包:

 

# 安装包上传至原安装包目录下 我的是/usr/local/ cd /usr/local/# 解压安装包xz -d mysql-8.0.19-linux-glibc2.12-x86_64.tar.xztar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar# 文件夹重命名为mysql8 mv mysql-8.0.19-linux-glibc2.12-x86_64 mysql8# 更改文件夹所属chown -R mysql.mysql /usr/local/mysql8/

 更改配置文件my.cnf

因5.7版本与8.0版本参数有所不同,为了能顺利升级,我们需要更改部分配置参数。主要注意sql_mode、basedir、密码认证插件及字符集设置,其他参数最好还是按照原5.7的来,不需要做调整。下面展示下更改后的配置文件:

注意:如果my.cnf 中配置了query_cache_size需要将其注销

 

# 最后几个for8.0的参数要格外注意[mysqld]user = mysqldatadir = /data/mysql/data  port = 3306socket = /data/mysql/tmp/mysql.sockpid-file  = /data/mysql/tmp/mysqld.pidtmpdir = /data/mysql/tmpskip_name_resolve = 1max_connections = 2000group_concat_max_len = 1024000lower_case_table_names = 1log_timestamps=SYSTEMmax_allowed_packet = 32Mbinlog_cache_size = 4Msort_buffer_size = 2Mread_buffer_size = 4Mjoin_buffer_size = 4Mtmp_table_size = 96Mmax_heap_table_size = 96Mmax_length_for_sort_data = 8096default_time_zone = '+8:00'#logsserver-id = 1003306log-error = /data/mysql/logs/error.logslow_query_log = 1slow_query_log_file = /data/mysql/logs/slow.loglong_query_time = 3log-bin = /data/mysql/logs/binlogbinlog_format = rowlog_bin_trust_function_creators = 1gtid_mode = ONenforce_gtid_consistency = ON#for8.0sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTIONcharacter-set-server = utf8collation_server = utf8_general_cibasedir = /usr/local/mysql8skip_ssldefault_authentication_plugin=mysql_native_password

 

 执行升级程序

所有前置工作准备好后就可以开始正式升级了,不过升级前还是建议先全库备份下。万事俱备后,按照如下指示进行正式升级。

 

# 进入原5.7 mysql命令行 正确关闭数据库mysql> select version();+------------+| version()  |+------------+| 5.7.23-log |+------------+1 row in set (0.00 sec)mysql> show variables like 'innodb_fast_shutdown';+----------------------+-------+| Variable_name| Value |+----------------------+-------+| innodb_fast_shutdown | 1 |+----------------------+-------+1 row in set (0.00 sec)# 确保数据都刷到硬盘上,更改成0mysql> set global innodb_fast_shutdown=0;Query OK, 0 rows affected (0.00 sec)mysql> shutdown;Query OK, 0 rows affected (0.00 sec)mysql> exitBye# 退出至终端 用mysql8.0.19客户端直接启动[root@centos ~]# /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql & [1] 23333[root@centos ~]# 2020-05-20T07:07:02.337626Z mysqld_safe Logging to '/data/mysql/logs/error.log'.2020-05-20T07:07:02.366244Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/data# 可观察下错误日志看是否报错 然后重新登录测试[root@centos ~]# mysql -uroot -p123456 mysql: [Waing] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 17Server version: 8.0.19 MySQL Community Server - GPLCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> select version();+-----------+| version() |+-----------+| 8.0.19|+-----------+1 row in set (0.00 sec)

 

 环境变量修改

因basedir由/usr/local/mysql变成了/usr/local/mysql8,故相关环境变量推荐修改下。可按照以下步骤来操作验证:

 

# 修改mysql服务启动项配置vi /etc/init.d/mysql# 修改basedir目录basedir=/usr/local/mysql8# 修改PATH变量vi /etc/profile # 将PATH中的/usr/local/mysql/bin改为/usr/local/mysql8/bin # 生效验证[root@centos ~]# source /etc/profile[root@centos ~]# which mysql/usr/local/mysql8/bin/mysql[root@centos ~]# mysql -Vmysql  Ver 8.0.19 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

 

 

总结:

至此,我们的数据库由5.7成功升级至8.0!对比MySQL安装过程及升级过程,发现二者很相似,其实升级过程并不复杂,复杂的是升级后的验证及兼容测试,特别是对于复杂的业务库,MySQL版本升级还是要小心的。真实环境建议先升级从库,验证无误后再逐步对主库进行升级。

参考链接:http://blog.itpub.net/31401187/viewspace-2693699/

 

作者:New_Jouey
来源链接:https://www.cnblogs.com/new-jouey/p/14453197.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/118234.html

标签:MySQL升级
分享给朋友:

“Mysql5.7升级至Mysql8过程” 的相关文章