02-mysql upgrade (rpm mode + binary mode upgrade)
-
- Upgrade method 1, rpm installation and upgrade
-
- 1. Download the mysql-5.7.42 installation package (mysql-5.7.37 upgrade mysql-5.7.42)
- 2. Back up the database, my.cnf file, and stop the mysql service (==Important==)
- 3. Check the current database version
- 3. Upload mysql-5.7.42-1.el7.x86_64.rpm-bundle.tar and decompress it
- 4. Check the packages related to installing MySQL
- 5. Upgrade and execute in order
- 6. Check and upgrade database dictionary
- 7. Start mysql and check the version and data
- Upgrade method two, binary installation and upgrade
-
- 1. Download the mysql-5.7.42 installation package (mysql-5.7.18 upgrades to mysql-5.7.42)
- 2. Back up the database (==Important==)
- 3. After the backup is completed, stop the mysql service
- 4. Unzip mysql-5.7.42
- 5. Back up the files in the installation directory of the old version of mysql-5.7.18.
- 6. Delete the old version installation directory /usr/local/mysql (bin, docs, include, lib, share, support-files, LICENSE, README);
- 7. Copy the newly decompressed mysql-5.7.42 directory to the original mysql installation directory (/usr/local/mysql/), and modify the file permissions.
- 8. Copy the newly decompressed mysqld version of mysql-5.7.42 to /etc/init.d/
- 9. Modify parameters
- 10. Start mysql and check the version
- 11. Run mysql_upgrade to check
- 12. Check account password, data, etc.
Upgrade method 1, rpm installation and upgrade
Before upgrading, read the mysql installation article: 01-mysql installation article (rpm installation + binary installation)
Pay attention to the relevant installation and configuration directories
1. Download the mysql-5.7.42 installation package (mysql-5.7.37 upgrade mysql-5.7.42)
address:https://downloads.mysql.com/archives/community/
mysql-5.7.42-1.el7.x86_64.rpm-bundle.tar
rpm 方式重要文件路径说明:
主要文件默认路径如下:
配置文件路径:/etc/my.cnf
数据存储目录:/var/lib/mysql
错误日志存储:/var/log/mysqld.log
socket文件路径:/var/lib/mysql/mysql.sock
如上参数均可以通过/etc/my.cnf参数配置文件查看和自定义。
2. Back up the database, my.cnf file, and stop the mysql service (important)
[root-mysql mysql-tar]# mysqldump -hlocalhost -uroot -p --all-databases > /home/user/db-test_back_2023.sql
[root-mysql mysql-tar]# cp /etc/my.cnf /etc/5.7.37_my.cnf
[root-mysql ~]# systemctl stop mysqld
3. Check the current database version
mysql> select@;
+-----------+
| @ |
+-----------+
| 5.7.37 |
+-----------+
1 row in set (0.00 sec)
mysql>
3. Upload mysql-5.7.42-1.el7.x86_64.rpm-bundle.tar and decompress it
[root-mysql ~]# mkdir mysql-bundle
[root-mysql ~]#
[root-mysql ~]# tar -xvf mysql-5.7.42-1.el7.x86_64.rpm-bundle.tar -C ~/mysql-bundle
mysql-community-client-5.7.42-1.el7.x86_64.rpm
mysql-community-common-5.7.42-1.el7.x86_64.rpm
mysql-community-devel-5.7.42-1.el7.x86_64.rpm
mysql-community-embedded-5.7.42-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.42-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.42-1.el7.x86_64.rpm
mysql-community-libs-5.7.42-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.42-1.el7.x86_64.rpm
mysql-community-server-5.7.42-1.el7.x86_64.rpm
mysql-community-test-5.7.42-1.el7.x86_64.rpm
[root-mysql ~]#
4. Check the packages related to installing MySQL
[root-mysql mysql-bundle]# rpm -qa|grep -i mysql
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
mysql-community-libs-5.7.37-1.el7.x86_64
[root-mysql mysql-bundle]#
5. Upgrade and execute in order
[root-mysql mysql-bundle]# ll
总用量 544432
-rw-r--r--. 1 7155 31415 29405072 3月 18 11:09 mysql-community-client-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 318948 3月 18 11:09 mysql-community-common-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 4430172 3月 18 11:09 mysql-community-devel-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 48202108 3月 18 11:10 mysql-community-embedded-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 23316088 3月 18 11:10 mysql-community-embedded-compat-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 133343532 3月 18 11:10 mysql-community-embedded-devel-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2747748 3月 18 11:10 mysql-community-libs-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1264424 3月 18 11:10 mysql-community-libs-compat-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 187276248 3月 18 11:10 mysql-community-server-5.7.42-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 127179748 3月 18 11:10 mysql-community-test-5.7.42-1.el7.x86_64.rpm
[root-mysql mysql-bundle]# rpm -Uvh mysql-community-server-5.7.42-1.el7.x86_64.rpm --force --nodeps
警告:mysql-community-server-5.7.42-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.42-1.e################################# [ 50%]
正在清理/删除...
2:mysql-community-server-5.7.37-1.e################################# [100%]
[root-mysql mysql-bundle]# rpm -Uvh mysql-community-client-5.7.42-1.el7.x86_64.rpm --force --nodeps
警告:mysql-community-client-5.7.42-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.42-1.e################################# [ 50%]
正在清理/删除...
2:mysql-community-client-5.7.37-1.e################################# [100%]
[root-mysql mysql-bundle]# rpm -Uvh mysql-community-libs-5.7.42-1.el7.x86_64.rpm --force --nodeps
警告:mysql-community-libs-5.7.42-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.42-1.el7################################# [ 50%]
正在清理/删除...
2:mysql-community-libs-5.7.37-1.el7################################# [100%]
[root-mysql mysql-bundle]# rpm -Uvh mysql-community-common-5.7.42-1.el7.x86_64.rpm --force --nodeps
警告:mysql-community-common-5.7.42-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.42-1.e################################# [ 50%]
正在清理/删除...
2:mysql-community-common-5.7.37-1.e################################# [100%]
[root-mysql mysql-bundle]#
6. Check and upgrade database dictionary
[root-mysql mysql-bundle]# mysql_upgrade -uroot -p123456
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
The sys schema is already up to date (version 1.5.2).
Checking databases.
db-test.user OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
[root-mysql mysql-bundle]#
7. Start mysql and check the version and data
[root-mysql ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42 MySQL Community Server (GPL)
Copyright (c) 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.
mysql> select@;
+-----------+
| @ |
+-----------+
| 5.7.42 |
+-----------+
1 row in set (0.00 sec)
mysql>
mysql> use db-test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user;
+----+-----------+------+--------+
| id | name | age | class |
+----+-----------+------+--------+
| 1 | 宋江 | 18 | 一班 |
| 2 | 卢俊义 | 20 | 二班 |
| 3 | 吴用 | 18 | 一班 |
| 4 | 公孙胜 | 19 | 二班 |
| 5 | 林冲 | 20 | 三班 |
| 6 | 呼延灼 | 16 | 四班 |
+----+-----------+------+--------+
6 rows in set (0.00 sec)
mysql>
Upgrade method two, binary installation and upgrade
1. Download the mysql-5.7.42 installation package (mysql-5.7.18 upgrades to mysql-5.7.42)
address:https://downloads.mysql.com/archives/community/
mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
2. Back up the database (important)
[root-mysql mysql-tar]# mysqldump -hlocalhost -uroot -p --all-databases > /home/user/myblog_back_2023.sql
3. After the backup is completed, stop the mysql service
[root-mysql mysql-tar]# systemctl stop mysqld
4. Unzip mysql-5.7.42
[root-mysql mysql-tar]# tar -zxvf mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
5. Back up the files in the installation directory of the old version of mysql-5.7.18.
[root-mysql mysql]# mkdir mysql_bk
[root-mysql mysql]# cp -R mysql/* mysql_bk
### 或者直接压缩
### tar -zcvf mysql.tar.gz mysql
[root@db-mysql bin]# tar zcf mysql.tar.gz mysql
6. Delete the old version installation directory /usr/local/mysql (bin, docs, include, lib, share, support-files, LICENSE, README);
[root-mysql mysql]# rm -rf bin
[root-mysql mysql]# rm -rf docs
[root-mysql mysql]# rm -rf include
[root-mysql mysql]# rm -rf lib
[root-mysql mysql]# rm -rf README
[root-mysql mysql]# rm -rf LICENSE
[root-mysql mysql]# rm -rf share
[root-mysql mysql]# rm -rf support-files
Back up mysqld under /etc/init.d/ first and then delete mysqld under /etc/init.d/
[root-mysql bin]# cd /etc/init.d/
[root-mysql init.d]# tar zcf mysqld_5.7.18.tar.gz mysqld
[root-mysql init.d]# rm -rf mysqld
7. Copy the newly decompressed mysql-5.7.42 directory to the original mysql installation directory (/usr/local/mysql/), and modify the file permissions.
[root-mysql mysql-tar]# mv mysql-5.7.42-linux-glibc2.12-x86_64/* /usr/local/mysql
[root@db-mysql mysql]# chown -R mysql:mysql /usr/local/mysql
8. Copy the newly decompressed mysqld version of mysql-5.7.42 to /etc/init.d/
[root-mysql mysql-5.7.42-linux-glibc2.12-x86_64]# cp support-files/mysql.server /etc/init.d/mysqld
9. Modify parameters
[root-mysql ~]# vi /etc/init.d/mysqld
Keep the same as the data directory of the original installation
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
10. Start mysql and check the version
[root-mysql ~]# systemctl start mysqld
[root-mysql ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since 三 2023-05-10 22:45:11 CST; 2min 36s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/mysqld.service
├─3279 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/db-mysql.pid
└─3494 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --use...
5月 10 22:45:10 db-mysql systemd[1]: Starting LSB: start and stop MySQL...
5月 10 22:45:11 db-mysql mysqld[3268]: Starting MySQL. SUCCESS!
5月 10 22:45:11 db-mysql systemd[1]: Started LSB: start and stop MySQL.
[root-mysql ~]#
[root-mysql ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.42, for linux-glibc2.12 (x86_64) using EditLine wrapper
[root-mysql ~]#
[root-mysql ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42 MySQL Community Server (GPL)
Copyright (c) 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.
mysql> show version();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'version()' at line 1
mysql>
mysql> select@;
+-----------+
| @ |
+-----------+
| 5.7.42 |
+-----------+
1 row in set (0.00 sec)
mysql>
11. Run mysql_upgrade to check
[root-mysql ~]# mysql_upgrade -uroot -p --force --skip-version-check
Enter password:
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
The sys schema is already up to date (version 1.5.1).
Checking databases.
myblog.album OK
myblog.article OK
myblog.comment OK
myblog.likes OK
myblog.user OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
[root-mysql ~]#