MySQL5.6.30升级到8.0.33

感谢大佬原创,为了防止丢失,收藏转载一下。

版权声明:本文为CSDN博主「简单爱你心所爱」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/evil_wdpp/article/details/132423750

注:原文作者设置的密码是orcle 。(一开始还以为是什么参数 -poracle)

5.7和8.0的默认字符集是utf8mb4,  5.6的是utf8
[mysqld]
#给mysql8.0 配一下mysql_native_password
default_authentication_plugin = mysql_native_password
sql_mode=NO_ENGINE_SUBSTITUTION
# 支持mysql8.0的python三方库
mysql-connector (待确定)         
mysql-connector-python  (待确定)
SQLAlchemy==1.3.4
PyMySQL==0.9.3

升级路线
1、支持从 MySQL 5.7 升级到 8.0。但是,仅在通用 (GA) 版本之间支持升级。对于 MySQL 8.0,需要从 MySQL 5.7 GA 版本(5.7.9 或更高版本)升级。不支持从 MySQL 5.7 的非 GA 版本升级。
2、建议在升级到下一个版本之前升级到最新版本。例如,在升级到 MySQL 8.0 之前升级到最新的 MySQL 5.7 版本。
3、不推荐:不支持跳过版本的升级(in-place),例如:不支持直接从 MySQL 5.6 升级到 8.0

环境准备
1、下载安装包
[root@mysql56 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
[root@mysql56 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@mysql56 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
[root@mysql56 ~]# ll -h mysql*
-rw-r–r–. 1 root root 301M Mar 3 2016 mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
-rw-r–r–. 1 root root 630M Mar 24 2020 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
-rw-r–r–. 1 root root 587M Mar 17 15:46 mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz

2、关闭防火墙
[root@mysql56 ~]# systemctl stop firewalld.service
[root@mysql56 ~]# systemctl disable firewalld.service

3、安装依赖包libaio
[root@mysql56 ~]# rpm -qa libaio
libaio-0.3.109-13.el7.x86_64
安装MySQL5.6.30
1、创建mysql用户
[root@mysql56 ~]# groupadd mysql
[root@mysql56 ~]# useradd -r -g mysql -s /bin/false mysql
[root@mysql56 ~]# id mysql
uid=998(mysql) gid=1000(mysql) groups=1000(mysql)

2、解压缩
[root@mysql56 ~]# tar -zxf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@mysql56 ~]# tar -zxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql56 ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz -C /usr/local

3、创建软链接
[root@mysql56 ~]# ln -s /usr/local/mysql-5.6.30-linux-glibc2.5-x86_64/ /usr/local/mysql
[root@mysql56 ~]# ll -h /usr/local/

4、创建数据目录
[root@mysql56 ~]# mkdir -p /data/mysql/3306/data
[root@mysql56 ~]# chown -R mysql:mysql /data/mysql/3306/data

5、创建配置文件
[root@mysql56 ~]# vim /etc/my.cnf

[client]
port=3306
default-character-set=utf8
socket=/data/mysql/3306/data/mysql.sock

[mysql]
prompt="\u@\h [\d]> "
default-character-set=utf8

[mysqld]
character-set-server=utf8
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
user=mysql
port=3306
server-id=3306
pid-file=/data/mysql/3306/data/mysql.pid
socket=/data/mysql/3306/data/mysql.sock
log-error=/data/mysql/3306/data/mysql.err
log-bin=mysql-bin
lower_case_table_names=1

6、初始化,5.6初始化使用的是mysql_install_db,它是一个Perl脚本,需要安装perl依赖包
[root@mysql56 ~]# yum install perl* -y
[root@mysql56 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data
Installing MySQL system tables…2023-08-19 08:01:30 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-08-19 08:01:30 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.30-log) starting as process 12786 …
OK

Filling help tables…2023-08-19 08:01:32 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-08-19 08:01:32 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.30-log) starting as process 12809 …
OK

7、启动数据库(个人补充:/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/3306/my.cnf 2>&1 > /dev/null &
[root@mysql56 ~]# /usr/local/mysql/bin/mysqld_safe &
[1] 12995
[root@mysql56 ~]# 230819 08:08:52 mysqld_safe Logging to ‘/data/mysql/3306/data/mysql.err’.
230819 08:08:52 mysqld_safe Starting mysqld daemon with databases from /data/mysql/3306/data

8、查看进程
[root@mysql56 ~]# ps -ef | grep mysql
root 12995 1595 0 08:08 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
mysql 13196 12995 1 08:08 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/localmysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/3306/data/mysql.err --pid-file=/data/mysql/3306/data/mysql.pid --socket=/data/mysql/3306/data/mysql.sock --port=3306
root 13219 1595 0 08:09 pts/2 00:00:00 grep --color=auto mysql

9、添加环境变量
[root@mysql56 ~]# vim .bash_profile
export MYSQL_HOME=/usr/local/mysql
export PATH= P A T H : PATH: PATH:MYSQL_HOME/bin
[root@mysql56 ~]# source .bash_profile

10、登录数据库,5.6初始化默认没有密码
[root@mysql56 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30-log MySQL Community Server (GPL)

Copyright © 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.

root@localhost [(none)]> select version();
±-----------+
| version() |
±-----------+
| 5.6.30-log |
±-----------+
1 row in set (0.00 sec)

root@localhost [(none)]> select user();
±---------------+
| user() |
±---------------+
| root@localhost |
±---------------+
1 row in set (0.00 sec)

11、设置密码
root@localhost [(none)]> set password=password(‘oracle’);
Query OK, 0 rows affected (0.00 sec)

[root@mysql56 ~]# mysql
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
[root@mysql56 ~]# mysql -poracle
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 3
Server version: 5.6.30-log MySQL Community Server (GPL)

Copyright © 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.

root@localhost [(none)]>
5.6.30升级到5.7.30
1、创建测试数据
root@localhost [test]> create table employees(id int primary key,name varchar(20));
Query OK, 0 rows affected (0.01 sec)

root@localhost [test]> show create table employees\G
*************************** 1. row ***************************
Table: employees
Create Table: CREATE TABLE employees (
id int(11) NOT NULL,
name varchar(20) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

root@localhost [test]> insert into employees values(1001,‘张三’),(1002,‘李四’);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

root@localhost [test]> select * from employees;
±-----±-------+
| id | name |
±-----±-------+
| 1001 | 张三 |
| 1002 | 李四 |
±-----±-------+
2 rows in set (0.00 sec)

2、升级前检查环境
[root@mysql56 ~]# mysqlcheck -poracle --all-databases --check-upgrade (个人补充:/usr/local/mysql/bin/mysqlcheck -S ./mysql_3306.sock -p --all-databases --check-upgrad -p
mysqlcheck: [Warning] Using a password on the command line interface can be insecure.
mysql.columns_priv Table is already up to date
mysql.component Table is already up to date
mysql.db Table is already up to date
mysql.default_roles Table is already up to date
mysql.engine_cost Table is already up to date
mysql.func Table is already up to date
mysql.general_log Table is already up to date
mysql.global_grants Table is already up to date
mysql.gtid_executed Table is already up to date
mysql.help_category Table is already up to date
mysql.help_keyword Table is already up to date
mysql.help_relation Table is already up to date
mysql.help_topic Table is already up to date
mysql.innodb_index_stats Table is already up to date
mysql.innodb_table_stats Table is already up to date
mysql.ndb_binlog_index Table is already up to date
mysql.password_history Table is already up to date
mysql.plugin Table is already up to date
mysql.procs_priv Table is already up to date
mysql.proxies_priv Table is already up to date
mysql.replication_asynchronous_connection_failover Table is already up to date
mysql.replication_asynchronous_connection_failover_managed Table is already up to date
mysql.replication_group_configuration_version Table is already up to date
mysql.replication_group_member_actions Table is already up to date
mysql.role_edges Table is already up to date
mysql.server_cost Table is already up to date
mysql.servers Table is already up to date
mysql.slave_master_info Table is already up to date
mysql.slave_relay_log_info Table is already up to date
mysql.slave_worker_info Table is already up to date
mysql.slow_log Table is already up to date
mysql.tables_priv Table is already up to date
mysql.time_zone Table is already up to date
mysql.time_zone_leap_second Table is already up to date
mysql.time_zone_name Table is already up to date
mysql.time_zone_transition Table is already up to date
mysql.time_zone_transition_type Table is already up to date
mysql.user Table is already up to date
sys.sys_config Table is already up to date
test.employees Table is already up to date

3、关闭数据库(个人补充:/usr/local/mysql/bin/mysqladmin -S ./mysql_3308.sock -p shutdown
root@localhost [test]> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)

[root@mysql56 ~]# /usr/local/mysql/support-files/mysql.server status
SUCCESS! MySQL running (13196)

[root@mysql56 ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL…230819 08:19:08 mysqld_safe mysqld from pid file /data/mysql/3306/data/mysql.pid ended
SUCCESS!
[1]+ Done /usr/local/mysql/bin/mysqld_safe

4、备份安装目录和数据目录
[root@mysql56 ~]# cd /usr/local/
[root@mysql56 local]# tar -czf mysql56.tar.gz mysql-5.6.30-linux-glibc2.5-x86_64/

[root@mysql56 ~]# cd /data/mysql/3306/
[root@mysql56 3306]# tar -czf data.tar.gz data/

[root@mysql56 3306]# ll -h
total 1.6M
drwxr-xr-x. 5 mysql mysql 257 Aug 19 08:27 data
-rw-r–r–. 1 root root 1.6M Aug 19 08:29 data.tar.gz

5、重新配置软连接
[root@mysql56 ~]# unlink /usr/local/mysql
[root@mysql56 ~]# ln -s /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64/ /usr/local/mysql

4、不需要初始化,启动MySQL(个人补充:/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/3306/my.cnf 2>&1 > /dev/null & )(需要改编码配置文件(5.7和8.0) !)
[root@mysql56 ~]# /usr/local/mysql/bin/mysqld_safe &

5、升级
[root@mysql56 ~]# mysql_upgrade -hlocalhost -uroot -poracle -S /data/mysql/3306/data/mysql.sock
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.
sys.sys_config OK
test.employees OK
Upgrade process completed successfully.
Checking if update is needed.

6、升级后重启
[root@mysql56 ~]# /usr/local/mysql/support-files/mysql.server restart
Shutting down MySQL…2023-08-19T00:59:01.174011Z mysqld_safe mysqld from pid file /data/mysql/3306/data/mysql.pid ended
SUCCESS!
Starting MySQL. SUCCESS!
[1]+ Done /usr/local/mysql/bin/mysqld_safe

7、登录数据库,可以看到版本已经升级到5.7.30
[root@mysql56 ~]# mysql -poracle
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 2
Server version: 5.7.30-log MySQL Community Server (GPL)

Copyright © 2000, 2020, 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.

root@localhost [(none)]> select version();
±-----------+
| version() |
±-----------+
| 5.7.30-log |
±-----------+
1 row in set (0.00 sec)

root@localhost [(none)]> select * from test.employees;
±-----±-------+
| id | name |
±-----±-------+
| 1001 | 张三 |
| 1002 | 李四 |
±-----±-------+
2 rows in set (0.00 sec)
5.7.30升级到8.0.33
1、在MySQL 8.0.16之前,需要手动调用mysql_upgrade工具升级performance_schema,INFORMATION_SCHEMA。从MySQL8.0.16开始,mysqld工具自动完成由之前的mysql_upgrade工具处理的所有任务,不再需要运行mysql_upgrade,且不建议使用mysql_upgrade
root@localhost [test]> select version();
±-----------+
| version() |
±-----------+
| 5.7.30-log |
±-----------+
1 row in set (0.00 sec)

2、创建测试数据
root@localhost [test]> create table departments(id int primary key,name varchar(20));
Query OK, 0 rows affected (0.02 sec)

root@localhost [test]> show create table departments\G
*************************** 1. row ***************************
Table: departments
Create Table: CREATE TABLE departments (
id int(11) NOT NULL,
name varchar(20) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.01 sec)

root@localhost [test]> insert into departments values(10,‘财务部’),(20,‘人力资源部’);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

root@localhost [test]> select * from departments;
±—±----------------+
| id | name |
±—±----------------+
| 10 | 财务部 |
| 20 | 人力资源部 |
±—±----------------+
2 rows in set (0.00 sec)

3、升级前检查
[root@mysql56 ~]# mysqlcheck -poracle --all-databases --check-upgrade
mysqlcheck: [Warning] Using a password on the command line interface can be insecure.
mysql.columns_priv Table is already up to date
mysql.component Table is already up to date
mysql.db Table is already up to date
mysql.default_roles Table is already up to date
mysql.engine_cost Table is already up to date
mysql.func Table is already up to date
mysql.general_log Table is already up to date
mysql.global_grants Table is already up to date
mysql.gtid_executed Table is already up to date
mysql.help_category Table is already up to date
mysql.help_keyword Table is already up to date
mysql.help_relation Table is already up to date
mysql.help_topic Table is already up to date
mysql.innodb_index_stats Table is already up to date
mysql.innodb_table_stats Table is already up to date
mysql.ndb_binlog_index Table is already up to date
mysql.password_history Table is already up to date
mysql.plugin Table is already up to date
mysql.procs_priv Table is already up to date
mysql.proxies_priv Table is already up to date
mysql.replication_asynchronous_connection_failover Table is already up to date
mysql.replication_asynchronous_connection_failover_managed Table is already up to date
mysql.replication_group_configuration_version Table is already up to date
mysql.replication_group_member_actions Table is already up to date
mysql.role_edges Table is already up to date
mysql.server_cost Table is already up to date
mysql.servers Table is already up to date
mysql.slave_master_info Table is already up to date
mysql.slave_relay_log_info Table is already up to date
mysql.slave_worker_info Table is already up to date
mysql.slow_log Table is already up to date
mysql.tables_priv Table is already up to date
mysql.time_zone Table is already up to date
mysql.time_zone_leap_second Table is already up to date
mysql.time_zone_name Table is already up to date
mysql.time_zone_transition Table is already up to date
mysql.time_zone_transition_type Table is already up to date
mysql.user Table is already up to date
sys.sys_config Table is already up to date
test.departments Table is already up to date
test.employees Table is already up to date

4、关闭数据库
root@localhost [test]> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)

[root@mysql56 ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL… SUCCESS!

5、备份安装目录和数据目录
[root@mysql56 ~]# cd /usr/local/
[root@mysql56 local]# tar -czf mysql57.tar.gz mysql-5.7.30-linux-glibc2.12-x86_64/
[root@mysql56 ~]# cd /data/mysql/3306/
[root@mysql56 3306]# tar -czf data57.tar.gz data/

6、重新配置软连接
[root@mysql56 ~]# unlink /usr/local/mysql
[root@mysql56 ~]# ln -s /usr/local/mysql-8.0.33-linux-glibc2.12-x86_64/ /usr/local/mysql

7、8.0启动MySQL时自动升级
[root@mysql56 ~]# /usr/local/mysql/bin/mysqld_safe &
[3] 29974
[root@mysql56 ~]# 2023-08-19T15:51:04.357860Z mysqld_safe Logging to ‘/data/mysql/3306/data/mysql.err’.
2023-08-19T15:51:04.400576Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/3306/data

[3] Done /usr/local/mysql/bin/mysqld_safe

不需要手动升级
[root@mysql56 ~]# mysql_upgrade -hlocalhost -uroot -poracle -S /data/mysql/3306/data/mysql.sock
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
The mysql_upgrade client is now deprecated. The actions executed by the upgrade client are now done by the server.
To upgrade, please start the new MySQL binary with the older data directory. Repairing user tables is done automatically. Restart is not required after upgrade.
The upgrade process automatically starts on running a new MySQL binary with an older data directory. To avoid accidental upgrades, please use the --upgrade=NONE option with the MySQL binary. The option --upgrade=FORCE is also provided to run the server upgrade sequence on demand.
It may be possible that the server upgrade fails due to a number of reasons. In that case, the upgrade sequence will run again during the next MySQL server start. If the server upgrade fails repeatedly, the server can be started with the --upgrade=MINIMAL option to start the server without executing the upgrade sequence, thus allowing users to manually rectify the problem.

8、查看版本
[root@mysql56 ~]# mysql -poracle
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 11
Server version: 8.0.33 MySQL Community Server - GPL

Copyright © 2000, 2023, Oracle and/or its affiliates.

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.

root@localhost [(none)]> select version();
±----------+
| version() |
±----------+
| 8.0.33 |
±----------+
1 row in set (0.00 sec)

root@localhost [(none)]> select * from test.departments;
±—±----------------+
| id | name |
±—±----------------+
| 10 | 财务部 |
| 20 | 人力资源部 |
±—±----------------+
2 rows in set (0.01 sec)

————————————————
版权声明:本文为CSDN博主「简单爱你心所爱」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/evil_wdpp/article/details/132423750

如果其他主机连不上mysql的话:
关一下防火墙:

sudo systemctl stop firewalld
sudo systemctl disable firewalld
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值