MySQL8.0 升级

MySQL8.0.30 升级到 MySQL8.0.32

备份旧数据

root@LAPTOP-FPIQJ438:/data/backup# xtrabackup --backup --user=root --password=123456 --socket=/tmp/mysql.sock --target-dir=/data/backup/
2024-01-08T16:46:38.987687+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/usr/local/mysql-8.0/data/
2024-01-08T16:46:38.988068+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --backup=1 --user=root --password=* --socket=/tmp/mysql.sock --target-dir=/data/backup/
xtrabackup version 8.0.35-30 based on MySQL server 8.0.35 Linux (x86_64) (revision id: 6beb4b49)
240108 16:46:39  version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;mysql_socket=/tmp/mysql.sock' as 'root'  (using password: YES).
Failed to connect to MySQL server as DBD::mysql module is not installed at - line 1548.
2024-01-08T16:46:39.050470+08:00 0 [Note] [MY-011825] [Xtrabackup] Connecting to MySQL server host: localhost, user: root, password: set, port: not set, socket: /tmp/mysql.sock
2024-01-08T16:46:39.058512+08:00 0 [Note] [MY-011825] [Xtrabackup] Using server version 8.0.30
2024-01-08T16:46:39.060647+08:00 0 [Note] [MY-011825] [Xtrabackup] Executing LOCK INSTANCE FOR BACKUP ...
2024-01-08T16:46:39.064725+08:00 0 [ERROR] [MY-011825] [Xtrabackup] Found tables with row versions due to INSTANT ADD/DROP columns
2024-01-08T16:46:39.064838+08:00 0 [ERROR] [MY-011825] [Xtrabackup] This feature is not stable and will cause backup corruption.
2024-01-08T16:46:39.064843+08:00 0 [ERROR] [MY-011825] [Xtrabackup] Please check https://docs.percona.com/percona-xtrabackup/8.0/em/instant.html for more details.
2024-01-08T16:46:39.064846+08:00 0 [ERROR] [MY-011825] [Xtrabackup] Tables found:
2024-01-08T16:46:39.064849+08:00 0 [ERROR] [MY-011825] [Xtrabackup] test/test
2024-01-08T16:46:39.064851+08:00 0 [ERROR] [MY-011825] [Xtrabackup] Please run OPTIMIZE TABLE or ALTER TABLE ALGORITHM=COPY on all listed tables to fix this issue.

可以发现出现 Found tables with row versions due to INSTANT ADD/DROP columns

错误,优化错误提示中 提到的表

优化表

mysql> OPTIMIZE table test;
+-----------+----------+----------+-------------------------------------------------------------------+
| Table     | Op       | Msg_type | Msg_text                                                          |
+-----------+----------+----------+-------------------------------------------------------------------+
| test.test | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| test.test | optimize | status   | OK                                                                |
+-----------+----------+----------+-------------------------------------------------------------------+
2 rows in set (0.06 sec)

继续备份

root@LAPTOP-FPIQJ438:/data/backup# xtrabackup --backup --user=root --password=123456 --socket=/tmp/mysql.sock --target-dir=/data/backup/

MySQL8.0.30配置文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password# datadir=/var/lib/mysql
# socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pidbasedir=/usr/local/mysql-8.0/
datadir=/usr/local/mysql-8.0/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4

记住 数据目录datadir ,数据库端口为 默认端口为 3306

获取新版安装包

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz

删除 旧版本的 安装目录文件

root@LAPTOP-FPIQJ438:/usr/local# rm -rf mysql-8.0
root@LAPTOP-FPIQJ438:/etc/init.d# cd /etc/init.d/
root@LAPTOP-FPIQJ438:/etc/init.d# rm -rf mysql

旧版本的配置文件可以不删除,新版本的可以直接使用旧版的配置文件

解压新版本安装包

root@LAPTOP-FPIQJ438:/usr/local# tar xvJf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
root@LAPTOP-FPIQJ438:/usr/local# mv mysql-8.0.32-linux-glibc2.12-x86_64 mysql-8.0

新版本初始化

初始化之前要将旧版本的数据目录下的数据文件全部删除,否则初始化失败

进入到新版本bin目录

root@LAPTOP-FPIQJ438:/usr/local# mkdri data
root@LAPTOP-FPIQJ438:chown -R mysql.mysql /usr/local/mysql-8.0
root@LAPTOP-FPIQJ438:/usr/local# cd mysql-8.0/bin/
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin#
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin#
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin#
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# pwd
/usr/local/mysql-8.0/bin

按照旧版本的配置文件初始化

./mysqld --user=mysql --basedir=/usr/local/mysql-8.0 --datadir=/usr/local/mysql-8.0/data/ --initialize

查看临时密码,通过配置文件中的 mysqld 进程日志 log-error=/var/log/mysqld.log

root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# vim /var/log/mysqld.log

临时密码为 rFf#SqPTw2q/

关闭旧版本数据库

root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::33060                :::*                    LISTEN      1402/mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      1402/mysqld
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin#
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin#
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin#
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# kill 1402

启动新版本数据库

进入到/usr/local/mysql-8.0

cp -a /usr/local/mysql-8.0/support-files/mysql.server /etc/init.d/mysql

该命令也会自动在/etc/init.d下创建mysql

授权启动

chmod +x /etc/init.d/mysql
service mysql start

登录修改密码

root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32Copyright (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>
mysql>
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)mysql> update user set host='%' where user='root';
ERROR 1046 (3D000): No database selected
mysql>
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql>
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)mysql>

还原旧版本的数据

service mysql stop                  --关闭新版数据库
rm -rf /usr/local/mysql-8.0/data/*  --删除新版数据库数据xtrabackup --prepare -uroot -p --target-dir=/data/backup/
xtrabackup --copy-back --target-dir=/data/backup/  --旧版数据库还原到新版数据库
chown -R mysql.mysql /usr/local/mysql-8.0

升级数据库验证

升级命令,目标版本大于8.0.16时,启动使用–upgrade=FORCE参数

root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# ./mysqld_safe --datadir=/usr/local/mysql-8.0/data/ --upgrade=FORCE &
[1] 1684
root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# 2024-01-09T06:03:41.032750Z mysqld_safe Logging to '/var/log/mysqld.log'.
2024-01-09T06:03:41.049302Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-8.0/data

查看

root@LAPTOP-FPIQJ438:/usr/local/mysql-8.0/bin# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32 MySQL Community Server - GPLCopyright (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>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)mysql>
mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql>
mysql>
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test           |
+----------------+
1 row in set (0.00 sec)mysql>
mysql>
mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    1 |
+------+
2 rows in set (0.00 sec)

可以查到 旧版 test 数据

注意

升级过程前,一定要备份数据,版本的升级方式有所差异

#8.0.16以后的版本
mysqladmin -u root -p shutdown
mysqld_safe --user=mysql --datadir=/path/to/8.0-datadir --upgrade=FORCE &#8.0.16之前的版本
mysql_upgrade -u root -p
mysqladmin -u root -p shutdown
mysqld_safe --user=mysql --datadir=/path/to/8.0-datadir &

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/334651.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

控制障碍函数(Control Barrier Function,CBF) 三、代码

三、代码实现 3.1、模型 这是一个QP问题,所以我们直接建模 这其实还是之前的那张图,我们把这个大的框架带入到之前的那个小车追击的问题中去,得到以下的一些具体的约束条件 CLF约束 L g V ( x ) u − δ ≤ − L f V ( x ) − λ V ( x ) …

Java药物不良反应ADR智能监测系统源码

药物不良反应(Adverse Drug Reaction,ADR)是指在使用合格药品时,在正常的用法和用量下出现的与用药目的无关的有害反应。这些反应往往因药物种类、使用方式、个体差异等因素而异,可能导致患者身体不适、病情恶化。 为保…

【STM32】STM32学习笔记-USART串口数据包(28)

00. 目录 文章目录 00. 目录01. 串口简介02. HEX数据包03. 文本数据包04. HEX数据包接收05. 文本数据包接收06. 预留07. 附录 01. 串口简介 串口通讯(Serial Communication)是一种设备间非常常用的串行通讯方式,因为它简单便捷,因此大部分电子设备都支持…

OceanBase数据库大赛落幕,“五点下班”队夺冠获10万奖金

近日,2023全国大学生计算机系统能力大赛暨第三届OceanBase数据库大赛落下帷幕。本届大赛共吸引海内外包括新加坡国立大学、清华大学、浙江大学、西安交通大学等268所高校的1154支队伍参赛,经过三个多月的比拼,来自西北工业大学的“五点下班”…

0002.ATMEGA8单片机采用LM60CIM3X检测温度必须要了解的内容

1.特性 校准后的线性比例因子为6.25mV/℃。 检测温度范围-40℃---125℃。 本次开发采用SOT-23封装。 2.主要技术规格: 精度: 25℃ ---2℃---3℃(max) -40℃-125℃---4℃(max) -25℃-125℃---3℃&#x…

使用Java连接MongoDB (6.0.12) 报错

报错: Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 352: Unsupported OP_QUERY command: create. 上图中“The client driver may require an upgrade”说明了“客户端驱动需要进行升级”,解…

Minecraft教程:使用MCSM面板搭建我的世界私服并实现远程联机

文章目录 前言1. 安装JAVA2. MCSManager安装3.局域网访问MCSM4.创建我的世界服务器5.局域网联机测试6.安装cpolar内网穿透7. 配置公网访问地址8.远程联机测试9. 配置固定远程联机端口地址9.1 保留一个固定tcp地址9.2 配置固定公网TCP地址9.3 使用固定公网地址远程联机 前言 Li…

C++学习笔记(十九)

一、vector容器 1. vector基本概念 功能:vector数据结构和数组非常相似,也称为单端数组 vector与普通数组区别:不同之处在于数组是静态空间,而vector可以动态扩展 动态扩展:并不是在原空间之后续接新空间&#xff…

关于Js深拷贝的三种方法详细讲解

目录 前言 一、pandas是什么? 二、使用步骤 1.利用函数递归来实现深拷贝 2.利用引入lodash包 3.利用JSON字符串转换 总结 前言 当涉及到JavaScript数据拷贝的时候,深拷贝是一个非常关键的概念。在JavaScript中,对象和数组被认为是引用类型&a…

Python学习之路-Hello Python

Python学习之路-Hello Python Python解释器 简介 前面说到Python是解释型语言,Python解释器的作用就是用于"翻译"Python程序。Python规定了一个Python语法规则,根据该规则可编写Python解释器。 常见的Python解释器 CPython:官方…

2024年跨境电商上半年营销日历,建议收藏

2024年伊始,跨境电商开启新一轮的营销竞技,那么首先需要客户需求,节假日与用户需求息息相关,那么接下来小编为大家整理2024上半年海外都有哪些节日和假期?跨境卖家如何见针对营销日历选品,助力卖家把握2024…

1878_emacs company backend的选择尝试

Grey 全部学习内容汇总: GitHub - GreyZhang/editors_skills: Summary for some common editor skills I used. 1872_emacs company backend的选择尝试 从C语言开发的使用场景角度,通过测试尝试看看这个company的backend应该来如何配置。 主题由来介…