MYSQL小版本升級(5.7.21至5.7.25)


1.環境確認

[root@mysql ~]# ps -ef |grep -i mysql
root 9173 1 0 2020 ? 00:00:00 /bin/sh /mysql/data/mysql-5.7.21/bin/mysqld_safe --datadir=/mysql/data/mysql-5.7.21/data --pid-file=/mysql/data/mysql-5.7.21/data/mysqld.pid
mysql 9367 9173 0 2020 ? 06:07:52 /mysql/data/mysql-5.7.21/bin/mysqld --basedir=/mysql/data/mysql-5.7.21 --datadir=/mysql/data/mysql-5.7.21/data --plugin-dir=/mysql/data/mysql-5.7.21/lib/plugin --user=mysql --log-error=/mysql/data/mysql-5.7.21/data/mysqld.log --pid-file=/mysql/data/mysql-5.7.21/data/mysqld.pid --socket=/tmp/mysql.sock --port=3306
root 17045 17002 0 09:36 pts/0 00:00:00 grep --color=auto -i mysql

mysql -uroot -pmysql@2020

mysql -e "SELECT table_schema,SUM(data_length+index_length)/1024/1024 AS total_mb,SUM(data_length)/1024/1024 AS data_mb,SUM(index_length)/1024/1024 AS index_mb, SUM(data_free)/1024/1024 AS free_mb,COUNT(*) AS tables_num,CURDATE() AS today FROM information_schema.tables where table_schema not in ('mysql','sys','information_schema','performance_schema') GROUP BY table_schema ORDER BY total_mb desc\G"
*************************** 1. row ***************************
table_schema: app_manager
total_mb: 153.42434692
data_mb: 138.15676880
index_mb: 15.26757813
free_mb: 14.00000000
tables_num: 19
today: 2021-06-07
*************************** 2. row ***************************
table_schema: lifeapp_config
total_mb: 0.14376068
data_mb: 0.11055756
index_mb: 0.03320313
free_mb: 0.00000000
tables_num: 8
today: 2021-06-07
2 rows in set (0.01 sec)

=============================


2.新環境准備

mkdir -p /mysql/data/mysql-5.7.25/data
chown -R mysql:mysql /mysql/data/mysql-5.7.25/
chmod 750 /mysql/data/mysql-5.7.25/

cd /mysql/data/
tar -zxf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql-5.7.25
chown -R mysql.mysql mysql-5.7.25

3.關閉原環境

tail -100f /mysql/data/mysql-5.7.21/data/mysqld.log
/mysql/data/mysql-5.7.21/bin/mysqladmin -uroot -p'mysql@2020' shutdown

cp /etc/my.cnf /etc/my.cnf.07bak
cp -rp /mysql/data/mysql-5.7.21/data/* /mysql/data/mysql-5.7.25/data/

4.啟動新環境

/mysql/data/mysql-5.7.25/mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysqld --basedir=/mysql/data/mysql-5.7.25 --datadir=/mysql/data/mysql-5.7.25/data --plugin-dir=/mysql/data/mysql-5.7.25/mysql-5.7.25-linux-glibc2.12-x86_64/lib/plugin --user=mysql --log-error=/mysql/data/mysql-5.7.25/data/mysqld.log --pid-file=/mysql/data/mysql-5.7.25/data/mysqld.pid --socket=/tmp/mysql.sock --port=3306 --skip-grant-tables --skip-networking &

 

5.升級數據字典

/mysql/data/mysql-5.7.25/mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysql_upgrade -S /tmp/mysql.sock

/mysql/data/mysql-5.7.25/mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysqladmin -S /tmp/mysql.sock -uroot -p'mysql@2020' shutdown

6.修改環境變量

vi /etc/profile
PATH=$PATH:/mysql/data/mysql-5.7.21/bin
改為
PATH=$PATH:/mysql/data/mysql-5.7.25/mysql-5.7.25-linux-glibc2.12-x86_64/bin

退出重新登陸加載環境變量並確認:
which mysql

7.修改參數文件

vi /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

basedir = /mysql/data/mysql-5.7.25
datadir = /mysql/data/mysql-5.7.25/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8

log-error = /mysql/data/mysql-5.7.25/data/mysqld.log
pid-file = /mysql/data/mysql-5.7.25/data/mysqld.pid

8.啟動環境

/mysql/data/mysql-5.7.25/mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysqld_safe --datadir=/mysql/data/mysql-5.7.25/data --pid-file=/mysql/data/mysql-5.7.25/data/mysqld.pid &

9.檢查確認

cat /etc/my.cnf

mysql -uroot -pmysql@2020
[root@mysql ~]# mysql -uroot -pmysql@2020
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 4
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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 table_schema,SUM(data_length+index_length)/1024/1024 AS total_mb,SUM(data_length)/1024/1024 AS data_mb,SUM(index_length)/1024/1024 AS index_mb, SUM(data_free)/1024/1024 AS free_mb,COUNT(*) AS tables_num,CURDATE() AS today FROM information_schema.tables where table_schema not in ('mysql','sys','information_schema','performance_schema') GROUP BY table_schema ORDER BY total_mb desc\G
*************************** 1. row ***************************
table_schema: app_manager
total_mb: 153.42434692
data_mb: 138.15676880
index_mb: 15.26757813
free_mb: 10.00000000
tables_num: 19
today: 2021-06-07
*************************** 2. row ***************************
table_schema: lifeapp_config
total_mb: 0.14376068
data_mb: 0.11055756
index_mb: 0.03320313
free_mb: 0.00000000
tables_num: 8
today: 2021-06-07
2 rows in set (0.01 sec)

總結:
1.升級前檢查庫的角色(主從),數據量的大小。數據量大可以采用這種方式,數據量小可以使用mysqldump進行導出導入。
2.升級重點就是執行新版本的初始化和upgrade腳本檢查。
3.本次環境安裝不標准,環境變量和my.cnf文件為聚堆全路徑,所以需要修改這兩項。規范安裝應該建立軟連接(ln -s mysql-5.7 /full_path ),無需進行修改。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM