本文主要是介绍mysql数据库8.0小版本原地升级,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
mysql数据库8.0小版本原地升级
- 准备工作
- 升级工作
- 停库
- 使用新版本软件启动数据库
- 更新环境变量
- 重启数据库
- 升级日志
- OS release: CentOS 7.9
- 升级前DB version: MySQL 8.0.30
- 数据库升级安装包:mysql-8.0.36-linux-glibc2.12-x86_64.tar.xz
- MySQL Shell安装包:mysql-shell-8.0.36-linux-glibc2.12-x86-64bit.tar.gz
准备工作
(1)修改认证插件
SQL> show variables like '%authentication_plugin%';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| default_authentication_plugin | mysql_native_password |
+-------------------------------+-----------------------+
1 row in set (0.00 sec)
出于安全因素考虑,my.cnf里的认证插件如果用的是mysql_native_password,建议替换为caching_sha2_password。
[mysqld]
default_authentication_plugin=caching_sha2_password
检查用户的认证插件:
SQL> select user,host,plugin from mysql.user;
+---------------------------+---------------+-----------------------+
| user | host | plugin |
+---------------------------+---------------+-----------------------+
| appuser | % | mysql_native_password |
| jeffrey | localhost | mysql_native_password |
| mysql_innodb_rs_101 | % | mysql_native_password |
| mysql_innodb_rs_173592206 | % | mysql_native_password |
| mysql_rcadmin | % | mysql_native_password |
| root | 127.0.0.1 | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
+---------------------------+---------------+-----------------------+
更新用户的认证插件:
SQL> ALTER USER 'jeffrey'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password';
(2)弃用的参数
MySQL 8.0中不再建议使用expire_logs_days
参数,而是使用binlog_expire_logs_seconds
来代替。
[mysqld]
binlog_expire_logs_seconds=604800 # 日志保留7天
(3)备份工具
利用备份工具对要升级的数据库进行全库备份。
🐯 MySQL 8.0.36不再支持mysqlpump工具。数据库备份请使用mysqldump、MySQL Shell或者xtrabackup的对应版本。
(4)统计数据量
--查询所有数据库的总大小
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from information_schema.tables;--统计每个库大小
select table_schema, count(*) tables,
concat(round(sum(table_rows)/1000,2),'千行') table_rows,
concat(round(sum(data_length)/(1024*1024),2),'M') data_size,
concat(round(sum(index_length)/(1024*1024),2),'M') idx_size,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size
from information_schema.tables
where table_schema not in ('information_schema','performance_schema','mysql','sys')
group by table_schema order by sum(data_length+index_length) desc;
(5)升级前检查
升级前的版本:
[mysql@host01 software]$ mysql -V
mysql Ver 8.0.30 for Linux on x86_64 (MySQL Community Server - GPL)
检查MySQL进程启动参数:
[mysql@host01 software]$ ps -ef | grep mysqld
/mysql/app/8.0/bin/mysqld_safe --defaults-file=/mydata/3306/my.cnf
/mysql/app/8.0/bin/mysqld --defaults-file=/mydata/3306/my.cnf --basedir=/mysql/app/8.0 --datadir=/mydata/3306/data --plugin-dir=/mysql/app/8.0/lib/plugin --log-error=/mydata/3306/err.log --open-files-limit=65535 --pid-file=/mydata/3306/runtime/mysql.pid --socket=/mydata/3306/runtime/mysql.sock --port=3306
检查环境变量:
[mysql@host01 ~]$ cat /home/mysql/.bash_profile
...export MYSQL_HOME=/mysql/app/8.0
export MYSQL_PORT=3306
export MYSQL_DATA=/mydata/${MYSQL_PORT}
export PATH=$MYSQL_HOME/bin:/mysql/util:/mysql/app/mysql-shell/bin:$PATH
export LD_LIBRARY_PATH=$MYSQL_HOME/lib:$LD_LIBRARY_PATH
使用mysqlcheck工具进行检查:
mysqlcheck -h127.0.0.1 -uroot -p --all-databases --check-upgrade
(6)下载安装包
MySQL社区版安装包:https://downloads.mysql.com/archives/community/
升级工作
停库
确认所有应用连接已断开,未提交的事务都已提交或者回滚。
--检查连接会话
SQL> show processlist;--检查未提交的XA事务
SQL> xa recover;
停止数据库:
mysqladmin -h127.0.0.1 -uroot shutdownps -ef | grep mysql
使用新版本软件启动数据库
解压8.0.36的安装文件到指定路径下:
tar -xzvf mysql-shell-8.0.36-linux-glibc2.12-x86-64bit.tar.gz -C /mysql/app/
tar -xJvf mysql-8.0.36-linux-glibc2.12-x86_64.tar.xz -C /mysql/app/cd /mysql/app
mv mysql-8.0.36-linux-glibc2.12-x86_64 mysql-8.0.36
mv mysql-shell-8.0.36-linux-glibc2.12-x86-64bit mysql-shell-8.0.36
备份配置文件:
cp /mydata/3306/my.cnf /home/mysql/my.cnf.bak
修改my.cnf
中的BASEDIR配置:
[mysqld]
#basedir=/mysql/app/8.0
basedir=/mysql/app/mysql-8.0.36
使用8.0.36的二进程文件启动数据库:
/mysql/app/mysql-8.0.36/bin/mysqld_safe --defaults-file=/mydata/3306/my.cnf
数据库启动过程中会自动升级数据库文件。
新开一个窗口观察升级过程中的报错信息:
tail -fn100 /mydata/3306/err.log
更新环境变量
更新数据库环境变量/home/mysql/.bash_profile
:
export MYSQL_HOME=/mysql/app/mysql-8.0.36
export MYSQL_PORT=3306
export MYSQL_DATA=/mydata/${MYSQL_PORT}
export PATH=$MYSQL_HOME/bin:/mysql/util:/mysql/app/mysql-shell-8.0.36/bin:$PATH
export LD_LIBRARY_PATH=$MYSQL_HOME/lib:$LD_LIBRARY_PATH
环境变量配置生效:
source /home/mysql/.bash_profile
检查数据库版本:
mysql -V
登录数据库检查版本信息:
SQL> select version();
重启数据库
停库:
SQL> shutdown;
起库:
mysqld_safe --defaults-file=/mydata/3306/my.cnf &
升级日志
升级过程中日志输出如下:
...
2024-08-29T09:45:47.430756+08:00 1 [Note] [MY-013327] [Server] MySQL server upgrading from version '80030' to '80036'.
2024-08-29T09:45:50.619324+08:00 1 [Note] [MY-012357] [InnoDB] Reading DD tablespace files
2024-08-29T09:45:50.621361+08:00 1 [Note] [MY-012356] [InnoDB] Scanned 13 tablespaces. Validated 13.
2024-08-29T09:46:06.824099+08:00 1 [Note] [MY-010006] [Server] Using data dictionary with version '80023'.
2024-08-29T09:46:06.907185+08:00 3 [Note] [MY-014066] [Server] Upgrading performance schema from version 80030 to 80033.
2024-08-29T09:46:09.654011+08:00 4 [System] [MY-013381] [Server] Server upgrade from '80030' to '80036' started.
2024-08-29T09:46:09.656741+08:00 4 [Note] [MY-013386] [Server] Running queries to upgrade MySQL server.
2024-08-29T09:46:21.691407+08:00 4 [Note] [MY-013387] [Server] Upgrading system table data.
2024-08-29T09:46:23.200896+08:00 4 [Note] [MY-013385] [Server] Upgrading the sys schema.
2024-08-29T09:46:24.626951+08:00 4 [Note] [MY-013400] [Server] Upgrade of help tables started.
2024-08-29T09:46:24.915297+08:00 4 [Note] [MY-013400] [Server] Upgrade of help tables completed.
2024-08-29T09:46:24.915519+08:00 4 [Note] [MY-013394] [Server] Checking 'mysql' schema.
2024-08-29T09:46:25.050329+08:00 4 [Note] [MY-013394] [Server] Checking 'sys' schema.
2024-08-29T09:46:25.098315+08:00 4 [System] [MY-013381] [Server] Server upgrade from '80030' to '80036' completed.
...
可以看到,升级过程中主要是升级了系统表、help表、performance_schema和sys schema等数据库内部对象。
References
【1】https://www.modb.pro/db/1788223768225189888
【2】https://forums.mysql.com/read.php?30,712008,722919#msg-722919
这篇关于mysql数据库8.0小版本原地升级的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!