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 ),无需进行修改。