亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

MySQL數(shù)據(jù)庫跨版本遷移的實現(xiàn)三種方式

 更新時間:2024年05月21日 10:24:59   作者:九皇叔叔  
本文主要介紹了MySQL數(shù)據(jù)庫跨版本遷移的實現(xiàn),主要包含mysqldump,物理文件遷移和原地升級三種,具有一定的參考價值,感興趣的可以了解一下

前言

MySQL數(shù)據(jù)庫不同版本之間進(jìn)行數(shù)據(jù)遷移。
遷移的方式,目前有三種方式:

  • mysqldump 進(jìn)行導(dǎo)出/導(dǎo)入
  • 物理文件遷移:拷貝 .ibd 文件至目標(biāo)庫,進(jìn)行導(dǎo)入.
  • 備份/恢復(fù) 原地升級

環(huán)境介紹

當(dāng)前環(huán)境如下:源庫
數(shù)據(jù)庫版本5.7.26
數(shù)據(jù)庫架構(gòu):主從
操作系統(tǒng)版本:Red Hat Enterprise Linux Server release 7.5 (Maipo)
節(jié)點信息

IP地址狀態(tài)
192.168.88.31主庫
192.168.88.32從庫

目標(biāo)庫
數(shù)據(jù)庫版本8.0.32
數(shù)據(jù)庫架構(gòu):主從
操作系統(tǒng)版本:Red Hat Enterprise Linux Server release 7.5 (Maipo)
節(jié)點信息

IP地址狀態(tài)
192.168.88.33主庫
192.168.88.34從庫

數(shù)據(jù)準(zhǔn)備

測試數(shù)據(jù):在源庫中創(chuàng)建 testdb 庫,其內(nèi)有兩張表:client、client_info ,每張表各 1000條 數(shù)據(jù)。

在這里插入圖片描述

[root@localhost][testdb]> select count(*) from client;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.00 sec)

[root@localhost][testdb]> select count(*) from client_info;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.00 sec)

[root@localhost][testdb]> 

數(shù)據(jù)遷移

在實際遷移過程中,應(yīng)用程序一般是會連接數(shù)據(jù)庫的、且實時會有數(shù)據(jù)進(jìn)來(即:數(shù)據(jù)庫實時會有新事務(wù)產(chǎn)生);
在遷移之前,會有統(tǒng)一步驟,例如:鎖業(yè)務(wù)賬號、設(shè)置只讀、鎖庫(非必須),若非生成環(huán)境,對數(shù)據(jù)一致性要求不高此步驟可忽略。在各遷移方式中不在分別寫入該步驟,現(xiàn)提前統(tǒng)一:

鎖賬號(業(yè)務(wù)賬號:fid_test

					-- 鎖住賬號
[root@localhost][mysql]> alter user fid_test@'%' account lock;
Query OK, 0 rows affected (0.00 sec)

					-- 查看賬號是否已被鎖
[root@localhost][mysql]> select user,host, account_locked from user where user = 'fid_test';
+----------+------+----------------+
| user     | host | account_locked |
+----------+------+----------------+
| fid_test | %    | Y              |
+----------+------+----------------+
1 row in set (0.00 sec)

-- 
-- 若需解鎖,執(zhí)行如下SQL:
					-- 解鎖賬號
[root@localhost][mysql]> alter user fid_test@'%' account unlock;
Query OK, 0 rows affected (0.00 sec)

[root@localhost][mysql]> select user,host, account_locked from user where user = 'fid_test';
+----------+------+----------------+
| user     | host | account_locked |
+----------+------+----------------+
| fid_test | %    | N              |
+----------+------+----------------+
1 row in set (0.00 sec)

設(shè)置只讀(主/從 各節(jié)點均需要單獨執(zhí)行)
如下是通過 SQL 語句進(jìn)行設(shè)置,數(shù)據(jù)庫一旦重啟、只讀將會失效。
若想更穩(wěn)妥一些,需修改配置文件my.cnf,該配置文件位置一般放在/etc/my.cnf(此處位置優(yōu)先加載),配置文件不同存放位置,可通過如下命令查看:

配置文件系列:只讀

[root@localhost mysql]# mysql --help | grep "Default options" -A 1
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 
[root@localhost mysql]# 

當(dāng)前配置文件存放在了/etc/my.cnf,使用 vi 命令編輯配置文件,修改 read_only 參數(shù),將其參數(shù)值設(shè)置為 1 即可。

				## 修改后的參數(shù)值如下:
[root@localhost mysql]# cat /etc/my.cnf | grep -i read_only
read_only                                   = 1
[root@localhost mysql]# 

SQL語句系列:只讀

					-- 設(shè)置為只讀;若需解除只讀:將 on 換成 off
[root@localhost][(none)]> set global read_only = on;
Query OK, 0 rows affected (0.00 sec)

[root@localhost][(none)]> 
[root@localhost][(none)]> show variables like 'read_only';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | ON    |
+---------------+-------+
1 row in set (0.00 sec)

鎖庫(主/從 各節(jié)點均需要單獨執(zhí)行)

					-- 鎖庫,**當(dāng)前會話一旦關(guān)閉:此鎖,將會自動釋放**。
[root@localhost][testdb]> flush tables with read lock;
Query OK, 0 rows affected (0.01 sec)
					-- 查看 GTID事務(wù)號是否變動
[root@localhost][mysql]> show master status;
+------------------+----------+--------------+------------------+--------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                          |
+------------------+----------+--------------+------------------+--------------------------------------------+
| mysql-bin.000005 |  1224273 |              |                  | 903316cd-27ca-11ee-a484-000c29ea6ce5:1-31
+------------------+----------+--------------+------------------+--------------------------------------------+
1 row in set (0.00 sec)

					-- 或者:嘗試產(chǎn)生一個事務(wù),將會有報錯提示:
[root@localhost][mysql]> create database test1001;
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock
[root@localhost][mysql]> 
					-- 在或者執(zhí)行:show processlist;
					-- 如果存在一個名為 FLUSH TABLES 的進(jìn)程,并且狀態(tài)顯示為 Waiting for table flush,那么表鎖定已經(jīng)生效了。
[root@localhost][(none)]> show processlist;
+----+-----------------+---------------------+------+------------------+------+---------------------------------------------------------------+--------------------------+
| Id | User            | Host                | db   | Command          | Time | State                                                         | Info                     |
+----+-----------------+---------------------+------+------------------+------+---------------------------------------------------------------+--------------------------+
|  1 | event_scheduler | localhost           | NULL | Daemon           |  616 | Waiting on empty queue                                        | NULL                     |
|  4 | fid_repluser    | 192.168.88.32:62190 | NULL | Binlog Dump GTID |  561 | Master has sent all binlog to slave; waiting for more updates | NULL                     |
|  5 | root            | localhost           | NULL | Query            |    0 | starting                                                      | show processlist         |
|  6 | root            | localhost           | NULL | Query            |    4 | Waiting for global read lock                                  | create database test1001 |
+----+-----------------+---------------------+------+------------------+------+---------------------------------------------------------------+--------------------------+
4 rows in set (0.00 sec)


--
-- 如果需要解鎖,執(zhí)行如下SQL:
[root@localhost][(none)]> unlock tables;
Query OK, 0 rows affected (0.00 sec)

方式一:mysqldump 遷移

在源庫中執(zhí)行如下 命令,進(jìn)行導(dǎo)出:

				##(1) 查看當(dāng)前所在目錄.
[root@localhost tmp]# pwd
/tmp

				##(2) 進(jìn)行數(shù)據(jù)導(dǎo)出.
[root@localhost tmp]# mysqldump -uroot -p123456 -B testdb --single-transaction --routines --triggers --events --set-gtid-purged=off > testdb.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost tmp]#
 
				##(3) 查看導(dǎo)出的文件.
[root@localhost tmp]# ls -lh testdb.sql 
-rw-r--r--. 1 root root 278K Mar 16 22:49 testdb.sql
[root@localhost tmp]# 

通過scp命令將文件傳輸給 目標(biāo)庫

[root@localhost tmp]# scp testdb.sql root@192.168.88.33:/tmp/
The authenticity of host '192.168.88.33 (192.168.88.33)' can't be established.
ECDSA key fingerprint is SHA256:oOGVJ0qhwef57brL+Gev6JYPQYIB7bGXqfCOPPwkkV8.
ECDSA key fingerprint is MD5:a0:c4:91:5a:5a:d1:3e:cb:6d:c8:07:6c:b8:f7:bb:66.
Are you sure you want to continue connecting (yes/no)? yes  ## 這里輸入 yes
Warning: Permanently added '192.168.88.33' (ECDSA) to the list of known hosts.
root@192.168.88.33's password:    ## 然后在輸入一次密碼,不會顯示、正常輸入即可。
testdb.sql                        100%  277KB   8.7MB/s   00:00    ## 看到進(jìn)度100%,說明傳輸完成.
[root@localhost tmp]# 

登錄目標(biāo)庫,先創(chuàng)建 testdb 數(shù)據(jù)庫

[root@localhost][(none)]> create database testdb;
Query OK, 1 row affected (0.00 sec)

目標(biāo)庫:進(jìn)行數(shù)據(jù)導(dǎo)入,命令如下:

[root@testdbmy01 ~]# mysql -uroot -p123456 testdb < /tmp/testdb.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@testdbmy01 ~]# 

目標(biāo)庫:驗證,確保數(shù)據(jù)遷移成功。

[root@localhost][(none)]> show tables from testdb;
+------------------+
| Tables_in_testdb |
+------------------+
| client           |
| client_info      |
+------------------+
2 rows in set (0.01 sec)

[root@localhost][(none)]> select count(*) from testdb.client;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.05 sec)

[root@localhost][(none)]> select count(*) from testdb.client_info;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.05 sec)

[root@localhost][(none)]> 

方式二:物理文件遷移

物理文件遷移這種玩法,是通過拷貝 .ibd 文件,那么也就意味著:這個參數(shù)innodb_file_per_table 是打開的狀態(tài)。

[root@localhost][(none)]> show variables like 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | ON    |
+-----------------------+-------+
1 row in set (0.00 sec)

每創(chuàng)建一張表,都會單獨存放在一個表空間中,存放在 datadir 這個變量的路徑中。
如下,可得知:當(dāng)前是存放在了/mysql/data/這個路徑中。

[root@localhost][(none)]> show variables like 'datadir';
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| datadir       | /mysql/data/ |
+---------------+--------------+
1 row in set (0.01 sec)

查看

[root@testdbmy01 ~]# ls -lh /mysql/data/testdb/* 
-rw-r-----. 1 mysql mysql 240K Mar 16 23:05 /mysql/data/testdb/client.ibd
-rw-r-----. 1 mysql mysql 240K Mar 16 23:05 /mysql/data/testdb/client_info.ibd
[root@testdbmy01 ~]# 

現(xiàn)開始進(jìn)行數(shù)據(jù)遷移步驟:

源庫:查看需要遷移表的結(jié)構(gòu)。將表結(jié)構(gòu)在 目標(biāo)庫 中進(jìn)行創(chuàng)建。

[root@localhost][testdb]> show create table client \G
*************************** 1. row ***************************
       Table: client
Create Table: CREATE TABLE `client` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
  `client_id` bigint(20) NOT NULL COMMENT 'ID編號',
  `user_no` varchar(30) DEFAULT NULL COMMENT '賬號',
  `user_password` varchar(60) DEFAULT NULL COMMENT '密碼',
  `nick_name` varchar(30) DEFAULT NULL COMMENT '昵稱',
  `real_name` varchar(30) DEFAULT NULL COMMENT '真實姓名',
  `created_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '創(chuàng)建時間',
  `upated_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新時間',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec)

[root@localhost][testdb]> show create table client_info \G
*************************** 1. row ***************************
       Table: client_info
Create Table: CREATE TABLE `client_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
  `client_info_id` bigint(20) NOT NULL COMMENT 'ID編號',
  `id_card_no` varchar(30) DEFAULT NULL COMMENT '身份證ID編號',
  `mobile_phone` varchar(30) DEFAULT NULL COMMENT '手機(jī)號碼',
  `gender` char(5) DEFAULT NULL COMMENT '性別',
  `height` int(11) DEFAULT NULL COMMENT '身高',
  `weight` int(11) DEFAULT NULL COMMENT '體重',
  `political` varchar(30) DEFAULT NULL COMMENT '政治面貌',
  `marital` varchar(30) DEFAULT NULL COMMENT '婚姻狀況',
  `hobby` varchar(50) DEFAULT NULL COMMENT '愛好',
  `created_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '創(chuàng)建時間',
  `upated_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新時間',
  `client_id` bigint(20) NOT NULL COMMENT '外鍵-客戶ID編號.',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec)

[root@localhost][testdb]> 

目標(biāo)庫:卸載表空間,執(zhí)行如下SQL

					-- 卸載 client 表的 表空間
[root@localhost][(none)]> alter table testdb.client discard tablespace;
Query OK, 0 rows affected (0.01 sec)
					-- 卸載 client_info 表的 表空間
[root@localhost][(none)]> alter table testdb.client_info discard tablespace;
Query OK, 0 rows affected (0.01 sec)

					-- 表空間卸載完成之后,表還是會存在的。
[root@localhost][(none)]> show tables from testdb;
+------------------+
| Tables_in_testdb |
+------------------+
| client           |
| client_info      |
+------------------+
2 rows in set (0.00 sec)

					-- 查看表空間之前的文件,已經(jīng)被刪除了。
[root@localhost][(none)]> system ls -lh /mysql/data/testdb/
total 0
[root@localhost][(none)]> 

源庫執(zhí)行 FLUSH TABLES ... FOR EXPORT , 該表這時候處于 quiesce 狀態(tài),只讀,且創(chuàng)建.cfg metadata文件

[root@localhost][testdb]> flush tables client for export;
Query OK, 0 rows affected (0.00 sec)

-- 執(zhí)行此之前,需執(zhí)行 unlock tables; 進(jìn)行解鎖。
-- 在解鎖之前,先將 client.cfg 文件 copy 走至目標(biāo)端。
[root@localhost][testdb]> flush tables client_info for export;
Query OK, 0 rows affected (0.00 sec)

上述sql執(zhí)行完成后,可看到生成的cfg文件

[root@localhost ~]# cd /mysql/data/testdb/ 
[root@localhost testdb]# ls -lh 
total 480K
-rw-r-----. 1 mysql mysql 8.8K Mar 16 22:04 client.frm
-rw-r-----. 1 mysql mysql 224K Mar 16 22:06 client.ibd
-rw-r-----. 1 mysql mysql 1.1K Mar 16 23:20 client_info.cfg  ##-- client.cfg 已經(jīng)拷貝至目標(biāo)端.
-rw-r-----. 1 mysql mysql 9.0K Mar 16 22:05 client_info.frm
-rw-r-----. 1 mysql mysql 224K Mar 16 22:06 client_info.ibd
-rw-r-----. 1 mysql mysql   67 Jul  8  2023 db.opt
[root@localhost testdb]# 

源庫:將源庫中的 .ibd 和 .cfg文件拷貝到目標(biāo)庫中,路徑:/mysql/data/testdb/

[root@localhost testdb]# scp client_info.cfg root@192.168.88.33:/mysql/data/testdb/
root@192.168.88.33's password: 
client_info.cfg                                100% 1119     3.6MB/s   00:00    
[root@localhost testdb]# 
[root@localhost testdb]# scp client_info.ibd root@192.168.88.33:/mysql/data/testdb/
root@192.168.88.33's password: 
client_info.ibd                                100%  224KB  67.4MB/s   00:00    
[root@localhost testdb]# 

目標(biāo)庫 導(dǎo)入表空間即可。
查看 /mysql/data/testdb 文件夾中已經(jīng)有相關(guān)文件了。

[root@testdbmy01 testdb]# pwd
/mysql/data/testdb

## 文件已經(jīng)存在
## 但是-注意:文件權(quán)限不對,當(dāng)前不修改;進(jìn)行導(dǎo)入、查看報錯日志(學(xué)習(xí)下)
[root@testdbmy01 testdb]# ls -lh
total 456K
-rw-r-----. 1 root root  810 Mar 16 23:28 client.cfg
-rw-r-----. 1 root root 224K Mar 16 23:28 client.ibd
-rw-r-----. 1 root root 1.1K Mar 16 23:27 client_info.cfg
-rw-r-----. 1 root root 224K Mar 16 23:28 client_info.ibd
[root@testdbmy01 testdb]# 

導(dǎo)入表空間

-- 發(fā)現(xiàn)導(dǎo)入表空間報錯,這個是因為 文件權(quán)限不對引起的。
-- 應(yīng)該將 .cfg 、.ibd 文件的權(quán)限(所屬用戶)修改為 mysql
[root@localhost][(none)]> alter table testdb.client import tablespace;
ERROR 1812 (HY000): Tablespace is missing for table `testdb`.`client`.
[root@localhost][(none)]> 

--
-- 修改權(quán)限
[root@localhost][(none)]> system chown mysql.mysql /mysql/data/testdb/*
[root@localhost][(none)]> system ls -lh /mysql/data/testdb/
total 456K
-rw-r-----. 1 mysql mysql  810 Mar 16 23:28 client.cfg
-rw-r-----. 1 mysql mysql 224K Mar 16 23:28 client.ibd
-rw-r-----. 1 mysql mysql 1.1K Mar 16 23:27 client_info.cfg
-rw-r-----. 1 mysql mysql 224K Mar 16 23:28 client_info.ibd
[root@localhost][(none)]> 

--
-- 再次嘗試導(dǎo)入表空間
[root@localhost][testdb]> alter table client import tablespace;
Query OK, 0 rows affected (0.03 sec)

[root@localhost][testdb]> 
[root@localhost][testdb]> alter table client_info import tablespace;
Query OK, 0 rows affected (0.01 sec)

在目標(biāo)庫,驗證:

[root@localhost][testdb]> select count(*) from client;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.05 sec)

[root@localhost][testdb]> 
[root@localhost][testdb]> select count(*) from client_info;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.05 sec)

[root@localhost][testdb]> 
[root@localhost][testdb]> select * from client limit 1 \G
*************************** 1. row ***************************
           id: 1
    client_id: 1
      user_no: iaMHg4Uh
user_password: 4tBiW078JrEQHqxHxb2kRMwdgCdcWqaC
    nick_name: 孤膽英雄
    real_name: 司端
 created_time: 2024-03-16 22:05:44
  upated_time: 2024-03-16 22:05:44
1 row in set (0.00 sec)

[root@localhost][testdb]> 

方式三:備份/恢復(fù) 原地升級

大致思路步驟:

  • 在源庫:備份全庫
  • 將源庫上 mysql5.7 版本相關(guān)文件,傳遞至目標(biāo)庫
  • 在目標(biāo)庫:先安裝mysql8.0的庫、然后鏟掉(庫、數(shù)據(jù)文件等;僅保留軟件)
  • 在目標(biāo)庫:用步驟2 傳遞來的文件:mysql5.7 版本,進(jìn)行恢復(fù),然后停庫。
  • 在目標(biāo)庫:用步驟3 保留的 MySQL8 版本軟啟動 步驟4 中恢復(fù)的數(shù)據(jù)文件。

數(shù)據(jù)遷移步驟:

源庫:全量備份。

DATE=`date +%Y%m%d%H`
mkdir -p /backup/$DATE
/usr/bin/mysqlbackup --user=root --password=123456 --compress --compress-level=9 --backup-dir=/backup/$DATE/ backup-and-apply-log 
# 輸出的日志中,務(wù)必不要有 error 報錯,看到 success 即可,部分日志如下:
... ... 
240316 23:56:32 MAIN    INFO: 1035 MB of data files compressed to 4785 kbytes (compression 99.55%).
240316 23:56:32 MAIN    INFO: Compress Apply Backup operation completed successfully.
mysqlbackup completed OK!

打包文件

## 打包全量備份的文件.
[root@localhost backup]# tar -cf 2024031623.tar 2024031623

## 打包 mysql5.7 版本的軟件
[root@localhost local]# tar cf mysql57.tar mysql/

源庫:傳遞文件至目標(biāo)庫

##(1) 將 mysql5.7 版本的軟件,傳遞至目標(biāo)庫
[root@localhost local]# scp mysql57.tar root@192.168.88.33:/soft/

##(2)將 全量備份文件 傳遞至目標(biāo)庫.
[root@localhost backup]# scp 2024031623.tar root@192.168.88.33:/backup/

##(3)將 mysql5.7 版本的 mysqlbackup 傳遞至目標(biāo)庫
[root@localhost backup]# scp /usr/bin/mysqlbackup root@192.168.88.33:/soft/mysqlbackup_57

##(4)將 mysql5.7 版本的配置文件 /etc/my.cnf 傳遞至目標(biāo)庫
[root@localhost backup]# scp /etc/my.cnf root@192.168.88.33:/etc/my_57.cnf

目標(biāo)庫:恢復(fù)5.7版本的庫。

解壓備份文件

[root@testdbmy01 soft]# cd /backup/
[root@testdbmy01 backup]# tar -xf 2024031623.tar 

解壓5.7版本的軟件

[root@testdbmy01 local]# cd /soft/
[root@testdbmy01 soft]# tar -xf mysql57.tar 
[root@testdbmy01 soft]# mv mysql mysql57

停止 mysql 8.0 軟件,并鏟除默認(rèn)的系統(tǒng)庫等文件.(建議:在鏟除之前可做下全量備份,此處省略.)

## 停掉 mysql8.0 版本軟件.
[root@testdbmy01 local]# service mysqld stop
Shutting down MySQL.. SUCCESS! 

## 鏟除 mysql8.0 版本相關(guān)文件
[root@testdbmy01 local]# rm -rf /mysql
[root@testdbmy01 local]# 

目標(biāo)庫 恢復(fù) 5.7 版本相關(guān)庫

## 創(chuàng)建數(shù)據(jù)庫所需要的安裝路徑
mkdir -p /mysql/{data,logs,binlog,tmp}
touch /mysql/logs/{mysql-error.log,mysql-slow.log}

## 修改 /etc/my_57.cnf 文件中的軟件路徑,改成 /soft/mysql57 
## mysql5.7 版本的軟件,放置在了 /soft/ 目錄中
[root@testdbmy01 mysql57]# cat /etc/my_57.cnf | grep -i basedir
basedir                                     = /soft/mysql57

## 恢復(fù)
/soft/mysqlbackup_57 --defaults-file=/etc/my_57.cnf --datadir=/mysql/data --uncompress --backup-dir=/backup/2024031623/ copy-back

## 修改權(quán)限
chown -R mysql.mysql /mysql

## 
## 用 mysql5.7 版本軟件啟動數(shù)據(jù)庫,檢查是否正常.
## 啟動數(shù)據(jù)庫.
/soft/mysql57/bin/mysqld --defaults-file=/etc/my_57.cnf --user=mysql

## 登錄數(shù)據(jù)庫進(jìn)行驗證.==>> 無問題.
[root@testdbmy01 soft]# mysql -uroot -p123456
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 3
Server version: 5.7.26-log MySQL Community Server (GPL)

Copyright (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.

[root@localhost][(none)]> 
[root@localhost][(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1001             |
| mysql              |
| performance_schema |
| sys                |
| t1                 |
| t2                 |
| tdb1               |
| tdb2               |
| test1001           |
| testdb             |
+--------------------+
11 rows in set (0.00 sec)

[root@localhost][(none)]> select count(*) from testdb.client;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.00 sec)
 
[root@localhost][(none)]> select count(*) from testdb.client_info;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.00 sec)

[root@localhost][(none)]> 
[root@localhost][(none)]> select  * from testdb.client limit 1\G
*************************** 1. row ***************************
           id: 1
    client_id: 1
      user_no: iaMHg4Uh
user_password: 4tBiW078JrEQHqxHxb2kRMwdgCdcWqaC
    nick_name: 孤膽英雄
    real_name: 司端
 created_time: 2024-03-16 22:05:44
  upated_time: 2024-03-16 22:05:44
1 row in set (0.00 sec)

[root@localhost][(none)]> 

目標(biāo)庫 停用 mysql5.7 版本啟動的庫,然后使用 mysql8.0 版本進(jìn)行啟動。

停止數(shù)據(jù)庫(5.7版本)

[root@localhost][(none)]> flush tables;
Query OK, 0 rows affected (0.00 sec)

[root@localhost][(none)]> shutdown;
Query OK, 0 rows affected (0.00 sec)

[root@localhost][(none)]> exit
Bye
[root@testdbmy01 soft]# 
[root@testdbmy01 soft]# ps -ef | grep mysql
root       5776   4323  0 00:31 pts/1    00:00:00 grep --color=auto mysql
[root@testdbmy01 soft]# 

使用 mysql8 版本軟件進(jìn)行啟動

[root@testdbmy01 soft]# service mysqld start
Starting MySQL......... SUCCESS! 
[root@testdbmy01 soft]# 
[root@testdbmy01 soft]# 
[root@testdbmy01 soft]# ps -ef | grep mysql
root       5834      1  0 00:31 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql/data --pid-file=/mysql/data/testdbmy01.pid
mysql      7204   5834 41 00:31 pts/1    00:00:07 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/logs/mysql-error.log --open-files-limit=65535 --pid-file=/mysql/data/testdbmy01.pid --socket=/mysql/tmp/mysql.sock --port=3306
root       7580   4323  0 00:31 pts/1    00:00:00 grep --color=auto mysql
[root@testdbmy01 soft]# 
[root@testdbmy01 soft]# 

登錄 mysql8 版本數(shù)據(jù)庫,經(jīng)驗證,無問題。

[root@testdbmy01 soft]# mysql -uroot -p123456
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 11
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (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.

[root@localhost][(none)]> 
[root@localhost][(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| db1001             |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| t1                 |
| t2                 |
| tdb1               |
| tdb2               |
| test1001           |
| testdb             |
+--------------------+
11 rows in set (0.01 sec)

[root@localhost][(none)]> 
[root@localhost][(none)]> select count(*) from testdb.client;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.04 sec)

[root@localhost][(none)]> select count(*) from testdb.client_info;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.05 sec)

[root@localhost][(none)]> 
[root@localhost][(none)]> select * from testdb.client limit 1 \G
*************************** 1. row ***************************
           id: 1
    client_id: 1
      user_no: iaMHg4Uh
user_password: 4tBiW078JrEQHqxHxb2kRMwdgCdcWqaC
    nick_name: 孤膽英雄
    real_name: 司端
 created_time: 2024-03-16 22:05:44
  upated_time: 2024-03-16 22:05:44
  1 row in set (0.00 sec)

[root@localhost][(none)]>

到此這篇關(guān)于MySQL數(shù)據(jù)庫跨版本遷移的實現(xiàn)的文章就介紹到這了,更多相關(guān)MySQL 跨版本遷移內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Mysql修改server uuid的方法分享

    Mysql修改server uuid的方法分享

    這篇文章主要給大家介紹了關(guān)于Mysql修改server uuid的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • mysql字符串拼接的幾種實用方式小結(jié)

    mysql字符串拼接的幾種實用方式小結(jié)

    在SQL語句中經(jīng)常需要進(jìn)行字符串拼接,下面這篇文章主要給大家介紹了關(guān)于mysql字符串拼接的幾種實用方式,文中通過圖文以及代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • MySQL動態(tài)修改varchar長度的方法

    MySQL動態(tài)修改varchar長度的方法

    這篇文章主要介紹了MySQL動態(tài)修改varchar長度的方法的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • 關(guān)于mysql基礎(chǔ)知識的介紹

    關(guān)于mysql基礎(chǔ)知識的介紹

    本篇文章是對mysql的基礎(chǔ)知識進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • 關(guān)于MySQL中的 like操作符詳情

    關(guān)于MySQL中的 like操作符詳情

    這篇文章主要介紹了MySQL之like操作符,當(dāng)對未知或者說知道某一部分的值進(jìn)行過濾時,可以使用like操作符;like操作符用于模糊匹配。下面我們一起進(jìn)入文章看看文章是我詳細(xì)內(nèi)容
    2021-11-11
  • MySQL用戶賬戶管理和權(quán)限管理深入講解

    MySQL用戶賬戶管理和權(quán)限管理深入講解

    這篇文章主要給大家介紹了關(guān)于MySQL用戶賬戶管理和權(quán)限管理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • MySql是否需要commit詳解

    MySql是否需要commit詳解

    在本篇文章里小編給大家分享了關(guān)于MySql是否需要commit的相關(guān)知識點內(nèi)容,需要的朋友們跟著操作下。
    2019-05-05
  • mysql5.6建立索引報錯1709問題及解決

    mysql5.6建立索引報錯1709問題及解決

    這篇文章主要介紹了mysql5.6建立索引報錯1709問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 淺談MySQL臨時表與派生表

    淺談MySQL臨時表與派生表

    MySQL在處理請求的某些場景中,服務(wù)器創(chuàng)建內(nèi)部臨時表。即表以MEMORY引擎在內(nèi)存中處理,或以MyISAM引擎儲存在磁盤上處理.如果表過大,服務(wù)器可能會把內(nèi)存中的臨時表轉(zhuǎn)存在磁盤上。
    2017-02-02
  • MySQL group_concat函數(shù)使用方法詳解

    MySQL group_concat函數(shù)使用方法詳解

    GROUP_CONCAT函數(shù)用于將GROUP BY產(chǎn)生的同一個分組中的值連接起來,返回一個字符串結(jié)果,接下來就給大家簡單的介紹一下MySQL group_concat函數(shù)的使用方法,需要的朋友可以參考下
    2023-07-07

最新評論