前言:
不知不觉,MySQL8.0已经发布好多个GA小版本了。目前互联网上也有很多关于MySQL8.0的内容了,MySQL8.0版本基本已到稳定期,相信很多小伙伴已经在接触8.0了。本篇文章主要介绍从5.7升级到8.0版本的过程及注意事项,有想做版本升级的小伙伴可以参考下。
首先,我们要大概了解下MySQL5.7和8.0有哪些不同,参考官方文档和其他网友文章,概括总结出MySQL8.0以下几点新特性:
根据版本变化及官方升级教程,列举出以下几点注意事项:
下面以Linux系统为例,展示下具体升级过程。我的系统是CentOS7.7,原版本是MySQL5.7.23,以In-Place方式直接升级到MySQL8.0.19。
2.1 下载解压安装包
官网下载对应版本的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.xz tar -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/
2.2 更改配置文件my.cnf
因5.7版本与8.0版本参数有所不同,为了能顺利升级,我们需要更改部分配置参数。主要注意sql_mode、basedir、密码认证插件及字符集设置,其他参数最好还是按照原5.7的来,不需要做调整。下面展示下更改后的配置文件:
# 最后几个for8.0的参数要格外注意 [mysqld] user = mysql datadir = /data/mysql/data port = 3306 socket = /data/mysql/tmp/mysql.sock pid-file = /data/mysql/tmp/mysqld.pid tmpdir = /data/mysql/tmp skip_name_resolve = 1 max_connections = 2000 group_concat_max_len = 1024000 lower_case_table_names = 1 log_timestamps=SYSTEM max_allowed_packet = 32M binlog_cache_size = 4M sort_buffer_size = 2M read_buffer_size = 4M join_buffer_size = 4M tmp_table_size = 96M max_heap_table_size = 96M max_length_for_sort_data = 8096 default_time_zone = '+8:00' #logs server-id = 1003306 log-error = /data/mysql/logs/error.log slow_query_log = 1 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 3 log-bin = /data/mysql/logs/binlog binlog_format = row log_bin_trust_function_creators = 1 gtid_mode = ON enforce_gtid_consistency = ON #for8.0 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION character-set-server = utf8 collation_server = utf8_general_ci basedir = /usr/local/mysql8 skip_ssl default_authentication_plugin=mysql_native_password
2.3 执行升级程序
所有前置工作准备好后就可以开始正式升级了,不过升级前还是建议先全库备份下。万事俱备后,按照如下指示进行正式升级。
# 进入原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) # 确保数据都刷到硬盘上,更改成0 mysql> 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> exit Bye # 退出至终端 用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: [Warning] 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 17 Server version: 8.0.19 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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() | +-----------+ | 8.0.19 | +-----------+ 1 row in set (0.00 sec)
2.4 环境变量修改
因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 -V mysql Ver 8.0.19 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
总结:
至此,我们的数据库由5.7成功升级至8.0!对比MySQL安装过程及升级过程,发现二者很相似,其实升级过程并不复杂,复杂的是升级后的验证及兼容测试,特别是对于复杂的业务库,MySQL版本升级还是要小心的。真实环境建议先升级从库,验证无误后再逐步对主库进行升级
转自
MySQL5.7升级到8.0过程详解 - MySQL技术 - 博客园
https://www.cnblogs.com/mysqljs/p/12936024.html