mysql 5.7.8_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.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/

更改配置文件my.cnf

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

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

# 最后几个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

执行升级程序

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

# 进入原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)

环境变量修改

因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版本升级还是要小心的。真实环境建议先升级从库,验证无误后再逐步对主库进行升级。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值