MySQL 8.0.21 deb安装方式升级到8.0.39 丝滑升级 保留数据 Ubuntu 22.04

一、升级背景

由于高危漏洞的问题,安全部门要求升级数据库。当前生产数据库版本是MySQL 8.0.21,索性就直接升级到最新版本8.0.39修复漏洞问题。因为不涉及大版本更新,所以直接采用覆盖安装的升级方式。亲测有效,大版本升级请自行测试。

二、当前环境

操作系统:Ubuntu 22.04.4 LTS

数据库版本:mysql Ver 8.0.21 for Linux on x86_64 社区版

安装方式:数据库采用离线deb文件安装

三、升级前的准备
3.1 初步检查

执行命令 mysqlcheck -u root -p --all-databases --check-upgrade

bash 复制代码
root@ysql-master:~$ mysqlcheck -u root -p --all-databases --check-upgrade
Enter password: 
invoice_check.emp                                  OK
invoice_check.invoice_checking_item                OK
invoice_check.issue_attach                         OK
invoice_check.opration_log                         OK
invoice_check.pcr_feedback                         OK
mysql.columns_priv                                 OK
mysql.component                                    OK
mysql.db                                           OK
mysql.default_roles                                OK
mysql.engine_cost                                  OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.global_grants                                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.password_history                             OK
mysql.plugin                                       OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.role_edges                                   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
sys.sys_config                                     OK
admin@cngscccw-vpd405:~$ 
3.1 备份数据库

所有操作前,请先做好充足的备份工作,数据无价,谨慎操作!!!

逻辑备份:使用mysqldump 备份整个数据库

目录备份:可以将数据目录进行备份,在相同环境下替换进行快速恢复

我建议是通过目录进行备份,可以达到快速恢复的目的,同时可以多备份几个目录

bash 复制代码
-- 停止数据库

systemctl stop mysqld

-- 安装目录备份 base dir

cp -r /usr/lib/mysql /usr/lib/mysql_bak_`date +%F`

-- 数据目录备份 data dir 

cp -r /data/mysql /data/mysql_bak_`date +%F`

-- 配置文件备份

cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf_bak_`date +%F`
3.4 设置mysql的关闭模式

确认innodb_fast_shutdown的值不是2,值是2,需要调整成1或0

通过命令查询 show variables like '%innodb_fast_shutdown%';

sql 复制代码
mysql> show variables like '%innodb_fast_shutdown%';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| innodb_fast_shutdown | 1     |
+----------------------+-------+
1 row in set (0.00 sec)

mysql> 

通过下面命令调整,我建议设置成1

sql 复制代码
SET GLOBAL innodb_fast_shutdown = 1;  -- fast shutdown
SET GLOBAL innodb_fast_shutdown = 0;  -- slow shutdown

如果是其他值,会导致关闭的时候存在中间日志文件,升级完恢复时会出现日志等报错信息

三、安装升级

查看已经安装的mysql软件包版本 dpkg -l | grep mysql

bash 复制代码
root@mysql-master:/opt/mysql# dpkg -l | grep mysql
ii  libmysqlclient-dev                     8.0.36-0ubuntu0.22.04.1                 amd64        MySQL database development files
ii  libmysqlclient21:amd64                 8.0.36-0ubuntu0.22.04.1                 amd64        MySQL database client library
ii  mysql-client                           8.0.21-1ubuntu20.04                     amd64        MySQL Client meta package depending on latest version
ii  mysql-common                           8.0.21-1ubuntu20.04                     amd64        Common files shared between packages
ii  mysql-community-client                 8.0.21-1ubuntu20.04                     amd64        MySQL Client
ii  mysql-community-client-core            8.0.21-1ubuntu20.04                     amd64        MySQL Client Core Binaries
ii  mysql-community-server                 8.0.21-1ubuntu20.04                     amd64        MySQL Server
ii  mysql-community-server-core            8.0.21-1ubuntu20.04                     amd64        MySQL Server Core Binaires
ii  mysql-server                           8.0.21-1ubuntu20.04                     amd64        MySQL Server meta package depending on latest version
root@ysql-master:/opt/mysql# 

下载8.0.39的deb文件并上传至服务器

安装升级,至少需要下面几个deb文件包,需要的可以留邮箱给我

bash 复制代码
# 文件是从mysql-server_8.0.39-1ubuntu22.04_amd64.deb-bundle.tar解压获取的

libmysqlclient21_8.0.39-1ubuntu22.04_amd64.deb    
mysql-community-client_8.0.39-1ubuntu22.04_amd64.deb          
mysql-community-server-core_8.0.39-1ubuntu22.04_amd64.deb
libmysqlclient-dev_8.0.39-1ubuntu22.04_amd64.deb  
mysql-community-client-core_8.0.39-1ubuntu22.04_amd64.deb     
mysql-server_8.0.39-1ubuntu22.04_amd64.deb
mysql-client_8.0.39-1ubuntu22.04_amd64.deb        
mysql-community-client-plugins_8.0.39-1ubuntu22.04_amd64.deb
mysql-common_8.0.39-1ubuntu22.04_amd64.deb        
mysql-community-server_8.0.39-1ubuntu22.04_amd64.deb

添加执行权限

chmod +x *.deb

安装数据库,安装中途会出现询问配置文件更新的问题,建议默认,直接回车,会保留原配置信息

dpkg -i *.deb

bash 复制代码
root@mysql-master:/opt/mysql# dpkg -i *.deb
(Reading database ... 115120 files and directories currently installed.)
Preparing to unpack libmysqlclient21_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking libmysqlclient21:amd64 (8.0.39-1ubuntu22.04) over (8.0.36-0ubuntu0.22.04.1) ...
Preparing to unpack libmysqlclient-dev_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking libmysqlclient-dev (8.0.39-1ubuntu22.04) over (8.0.36-0ubuntu0.22.04.1) ...
Preparing to unpack mysql-client_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-client (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Preparing to unpack mysql-common_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-common (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Preparing to unpack mysql-community-client_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-client (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Preparing to unpack mysql-community-client-core_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-client-core (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Selecting previously unselected package mysql-community-client-plugins.
Preparing to unpack mysql-community-client-plugins_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-client-plugins (8.0.39-1ubuntu22.04) ...
Preparing to unpack mysql-community-server_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-server (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Preparing to unpack mysql-community-server-core_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-server-core (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Preparing to unpack mysql-server_8.0.39-1ubuntu22.04_amd64.deb ...
Unpacking mysql-server (8.0.39-1ubuntu22.04) over (8.0.21-1ubuntu20.04) ...
Setting up mysql-common (8.0.39-1ubuntu22.04) ...
Installing new version of config file /etc/mysql/conf.d/mysql.cnf ...
Installing new version of config file /etc/mysql/my.cnf.fallback ...
Setting up mysql-community-client-plugins (8.0.39-1ubuntu22.04) ...
Setting up mysql-community-server-core (8.0.39-1ubuntu22.04) ...
Setting up libmysqlclient21:amd64 (8.0.39-1ubuntu22.04) ...
Setting up libmysqlclient-dev (8.0.39-1ubuntu22.04) ...
Setting up mysql-community-client-core (8.0.39-1ubuntu22.04) ...
Setting up mysql-community-client (8.0.39-1ubuntu22.04) ...
Installing new version of config file /usr/share/mysql-8.0/charsets/armscii8.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/ascii.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp1250.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp1251.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp1256.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp1257.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp850.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp852.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/cp866.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/dec8.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/geostd8.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/greek.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/hebrew.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/hp8.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/Index.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/keybcs2.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/koi8r.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/koi8u.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/latin1.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/latin2.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/latin5.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/latin7.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/macce.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/macroman.xml ...
Installing new version of config file /usr/share/mysql-8.0/charsets/swe7.xml ...
Setting up mysql-client (8.0.39-1ubuntu22.04) ...
Setting up mysql-community-server (8.0.39-1ubuntu22.04) ...

Configuration file '/etc/apparmor.d/usr.sbin.mysqld'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** usr.sbin.mysqld (Y/I/N/O/D/Z) [default=N] ? 
Installing new version of config file /etc/mysql/mysql.cnf ...

Configuration file '/etc/mysql/mysql.conf.d/mysqld.cnf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** mysqld.cnf (Y/I/N/O/D/Z) [default=N] ? 
Setting up mysql-server (8.0.39-1ubuntu22.04) ...
Processing triggers for libc-bin (2.35-0ubuntu3.7) ...
Processing triggers for man-db (2.10.2-1) ...

root@mysql-master:/

安装升级完成会出现自动启动数据库

查看数据库状态 systemctl status mysql

bash 复制代码
root@mysql-master:/opt/mysql# date
Fri Sep  6 04:17:41 PM CST 2024
root@cngscccw-vpd405:/opt/mysql# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-09-06 16:04:29 CST; 13min ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 2303 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 2343 (mysqld)
     Status: "Server is operational"
      Tasks: 40 (limit: 9389)
     Memory: 871.9M
        CPU: 2.894s
     CGroup: /system.slice/mysql.service
             └─2343 /usr/sbin/mysqld

Sep 06 16:04:28 cngscccw-vpd405 systemd[1]: Starting MySQL Community Server...
Sep 06 16:04:29 cngscccw-vpd405 systemd[1]: Started MySQL Community Server.
root@mysql-master:/opt/mysql# 

检查各项配置文件是否有问题

bash 复制代码
# 检查各项配置文件

vim /etc/apparmor.d/usr.sbin.mysqld

vim /etc/mysql/mysql.conf.d/mysqld.cnf

查看log日志文件,升级是否有异常错误

bash 复制代码
root@mysql-master:/opt/mysql# cat /var/log/mysql/error.log
2024-09-06T08:04:20.065729Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2024-09-06T08:04:20.065742Z 0 [Warning] [MY-011070] [Server] 'binlog_format' is deprecated and will be removed in a future release.
2024-09-06T08:04:20.065757Z 0 [Warning] [MY-000081] [Server] option 'max_binlog_size': unsigned value 2147483648 adjusted to 1073741824.
2024-09-06T08:04:20.065806Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2024-09-06T08:04:20.068356Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.39) starting as process 1929
2024-09-06T08:04:20.076229Z 0 [Warning] [MY-013907] [InnoDB] Deprecated configuration parameters innodb_log_file_size and/or innodb_log_files_in_group have been used to compute innodb_redo_log_capacity=2147483648. Please use innodb_redo_log_capacity instead.
2024-09-06T08:04:20.077956Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-09-06T08:04:20.927403Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-09-06T08:04:20.934665Z 1 [System] [MY-011090] [Server] Data dictionary upgrading from version '80021' to '80023'.
2024-09-06T08:04:21.889061Z 1 [System] [MY-013413] [Server] Data dictionary upgrade from version '80021' to '80023' completed.
2024-09-06T08:04:23.373159Z 4 [System] [MY-013381] [Server] Server upgrade from '80021' to '80039' started.
2024-09-06T08:04:25.916970Z 4 [System] [MY-013381] [Server] Server upgrade from '80021' to '80039' completed.
2024-09-06T08:04:26.006106Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-09-06T08:04:26.006144Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-09-06T08:04:26.030247Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2024-09-06T08:04:26.030298Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.39'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
2024-09-06T08:04:26.616365Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.39).
2024-09-06T08:04:28.061804Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.39)  MySQL Community Server - GPL.
2024-09-06T08:04:28.501480Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2024-09-06T08:04:28.501493Z 0 [Warning] [MY-011070] [Server] 'binlog_format' is deprecated and will be removed in a future release.
2024-09-06T08:04:28.501513Z 0 [Warning] [MY-000081] [Server] option 'max_binlog_size': unsigned value 2147483648 adjusted to 1073741824.
2024-09-06T08:04:28.501562Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2024-09-06T08:04:28.503793Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.39) starting as process 2343
2024-09-06T08:04:28.510657Z 0 [Warning] [MY-013907] [InnoDB] Deprecated configuration parameters innodb_log_file_size and/or innodb_log_files_in_group have been used to compute innodb_redo_log_capacity=2147483648. Please use innodb_redo_log_capacity instead.
2024-09-06T08:04:28.512347Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-09-06T08:04:29.010644Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-09-06T08:04:29.174284Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-09-06T08:04:29.174330Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-09-06T08:04:29.200195Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2024-09-06T08:04:29.200275Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.39'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
root@mysql-master:/opt/mysql#

到此升级完成!

四、查看版本

再次查看已经安装的mysql软件包版本

bash 复制代码
root@mysql-master:/opt/mysql# dpkg -l | grep mysql
ii  libmysqlclient-dev                     8.0.39-1ubuntu22.04                     amd64        MySQL development headers
ii  libmysqlclient21:amd64                 8.0.39-1ubuntu22.04                     amd64        MySQL shared client libraries
ii  mysql-client                           8.0.39-1ubuntu22.04                     amd64        MySQL Client meta package depending on latest version
ii  mysql-common                           8.0.39-1ubuntu22.04                     amd64        Common files shared between packages
ii  mysql-community-client                 8.0.39-1ubuntu22.04                     amd64        MySQL Client
ii  mysql-community-client-core            8.0.39-1ubuntu22.04                     amd64        MySQL Client Core Binaries
ii  mysql-community-client-plugins         8.0.39-1ubuntu22.04                     amd64        MySQL Client plugin
ii  mysql-community-server                 8.0.39-1ubuntu22.04                     amd64        MySQL Server
ii  mysql-community-server-core            8.0.39-1ubuntu22.04                     amd64        MySQL Server Core Binaires
ii  mysql-server                           8.0.39-1ubuntu22.04                     amd64        MySQL Server meta package depending on latest version
root@mysql-master:/opt/mysql# 

查看数据库版本 mysqld --version

bash 复制代码
oot@cngscccw-vpd405:/opt/mysql#  mysqld --version
/usr/sbin/mysqld  Ver 8.0.39 for Linux on x86_64 (MySQL Community Server - GPL)
root@cngscccw-vpd405:/opt/mysql
五、验证数据库

省略,自己连接到数据库,检查原来的数据情况。

相关推荐
weixin_4493108424 分钟前
高效集成:聚水潭采购数据同步到MySQL
android·数据库·mysql
CodingBrother25 分钟前
MySQL 和 PostgreSQL 的使用案例
mysql·adb·postgresql
Cachel wood1 小时前
Github配置ssh key原理及操作步骤
运维·开发语言·数据库·windows·postgresql·ssh·github
standxy1 小时前
如何将钉钉新收款单数据高效集成到MySQL
数据库·mysql·钉钉
Narutolxy2 小时前
MySQL 权限困境:从权限丢失到权限重生的完整解决方案20241108
数据库·mysql
Venchill3 小时前
安装和卸载Mysql(压缩版)
数据库·mysql
Humbunklung3 小时前
一种EF(EntityFramework) MySQL修改表名去掉dbo前缀的方法
数据库·mysql·c#
PGCCC3 小时前
【PGCCC】postgresql 缓存池并发设计
数据库·缓存·postgresql
小爬虫程序猿4 小时前
如何利用Python解析API返回的数据结构?
数据结构·数据库·python
wowocpp5 小时前
查看 磁盘文件系统格式 linux ubuntu blkid ext4
linux·数据库·ubuntu