mysql大型資料庫遷移,mysql 數據遷移

本文目錄一覽:

mysql怎麼遷移資料庫

第一種方案的優點:會重建數據文件,減少數據文件的佔用空間。

第一種方案的缺點:時間佔用長。(導入導出都需要很長的時間,並且導出後的文件還要經過網路傳輸,也要佔用一定的時間。)

第二種方案的優點:設置完成後傳輸無人值守

第二種方案的缺點:

設置繁瑣。

傳輸中網路出現異常,不能及時的被發現,並且會一直停留在數據傳輸的狀態不能被停止,如不仔細觀察不會被發現異常。

傳輸相對其他fang時間長。

異常後很難從異常的位置繼續傳輸。

第三種方案的優點:時間佔用短,文件可斷點傳輸。操作步驟少。(絕大部分時間都是在文件的網路傳輸)

第三種方案的缺點:可能引起未知問題,暫時未發現。

怎麼將mysql資料庫轉移到另一台電腦上。可以整個mysql安裝目錄一起轉移么

mysql要轉換到另一台機器上面,最重要的要考慮以下幾個問題

1、資料庫使用什麼存儲引擎,如果是myisam的話,可以把data目錄複製移走。但如果是innodb的話,千萬不要用這種方法,會存在種種問題的。至於innodb引myisam的區別,百度一下詳細點。

2、本地的操作系統是否引目標操作系統相同,如果是linux與windows之間的轉移,因為平台的的不台,注意大小寫表名欄位的兼容性。也可以在my.ini或者my.cnf中忽略大小寫。

3、比較安全的做法,還是用mysqldump的方法導出來,再用mysqldump的方法導進去,這是一種比較保險安全兼容性高的做法,請考慮。

如果還有什麼疑問,歡迎追問。

如何遷移MySQL資料庫

caching_sha2_password認證插件提供更多的密碼加密方式,並且在加密方面具有更好的表現,目前MySQL 8.0選用caching_sha2_password作為默認的認證插件,MySQL 5.7的認證插件是MySQL_native_password。如果客戶端版本過低,會造成無法識別MySQL 8.0的加密認證方式,最終導致連接問題。

MySQL存儲引擎現在負責提供自己的分區處理程序,而MySQL伺服器不再提供通用分區支持,InnoDB和NDB是唯一提供MySQL 8.0支持的本地分區處理程序的存儲引擎。 如果分區表用的是別的存儲引擎,存儲引擎必須進行修改。要麼將其轉換為InnoDB或NDB,要麼刪除其分區。通過MySQLdump從5.7獲取的備份文件,在導入到8.0環境前,需要確保創建分區表語句中指定的存儲引擎必須支持分區,否則會報錯。

MySQL 8.0的默認字符集utf8mb4,可能會導致之前數據的字符集跟新建對象的字符集不一致,為了避免新舊對象字符集不一致的情況,可以在配置文件將字符集和校驗規則設置為舊版本的字符集和校驗規則。

MySQL 8.0啟動使用的lower_case_table_names值必須跟初始化時使用的一致。使用不同的設置重新啟動伺服器會引入與標識符的排序和比較方式不一致的問題。

 lower_case_table_names 

要避免MySQL 8.0上的啟動失敗,MySQL配置文件中的sql_mode系統變數不能包含NO_AUTO_CREATE_USER。

從MySQL 5.7.24和MySQL 8.0.13開始,MySQLdump從存儲程序定義中刪除了NO_AUTO_CREATE_USER。必須手動修改使用早期版本的MySQLdump創建的轉儲文件,以刪除NO_AUTO_CREATE_USER。

在MySQL 8.0.11中,刪除了這些不推薦使用的兼容性SQL Mode:DB2,MAXDB,MSSQL,MySQL323,MySQL40,ORACLE,POSTGRESQL,NO_FIELD_OPTIONS,NO_KEY_OPTIONS,NO_TABLE_OPTIONS。從5.7到8.0的複製場景中,如果語句使用到廢棄的SQL Mode會導致複製異常。

在執行到MySQL 8.0.3或更高版本的in-place升級時,BACKUP_ADMIN許可權自動授予具有RELOAD許可權的用戶。

本文對MySQL 5.7到MySQL 8.0的升級過程中出現部分易出現問題進行整理:升級對MySQL版本的要求、升級都做了哪些內容、資料庫升級做了哪些步驟以及注意事項,希望對大家版本升級有幫助。

MySQL8數據遷移大表捷徑【表空間遷移】

0. 目標端必須有同名表,沒有則建一個空表;

####################################

1、 源端文件準備

源端: 

   flush tables t for export; 

複製 

t.ibd, t.cfg到目標端。 

###############################

flush tables tt7   for export; 

cp  tt7*   ../ops

2、 目標端存在同樣的表則丟棄原來的數據文件

目標端: 

 alter table tt7  discard tablespace;

3、 目標端載入新的數據文件 t.ibd

alter table tt7 import tablespace; 

4、源端釋放鎖

源端: 

unlock tables; 

過程中主要異常處理:

#####################################################

SELECT  * FROM   ops2.tt7    ;

SELECT  * FROM   ops.tt7    ;

import tablespace報錯:

mysql alter table tt7 import tablespace; 

ERROR 1812 (HY000): Tablespace is missing for table ops.tt7.

確認再相應的目錄存在兩個文件

確認屬主和許可權

#####################################################

過程

[root@qaserver120 ops]# ll

total 80

drwxr-xr-x 2 root  root      36 Dec  2 21:42 000

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

[root@qaserver120 ops]# 

[root@qaserver120 ops]# 

[root@qaserver120 ops]# 

[root@qaserver120 ops]# cp 000

[root@qaserver120 ops]# ll

drwxr-xr-x 2 root  root      36 Dec  2 21:42 000

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—– 1 root  root     627 Dec  2 21:45 tt7.cfg

-rw-r—– 1 root  root  114688 Dec  2 21:45 tt7.ibd

[root@qaserver120 ops]# chown mysql.mysql tt7*

[root@qaserver120 ops]# 

[root@qaserver120 ops]# ll

drwxr-xr-x 2 root  root      36 Dec  2 21:42 000

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—– 1 mysql mysql    627 Dec  2 21:45 tt7.cfg

-rw-r—– 1 mysql mysql 114688 Dec  2 21:46 tt7.ibd

[root@qaserver120 ops]# 

#####################################################

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

| tt7           |

+—————+

2 rows in set (0.00 sec)

mysql select * from tt7;

ERROR 1814 (HY000): Tablespace has been discarded for table ‘tt7’

mysql alter table tt7 import tablespace; 

ERROR 1812 (HY000): Tablespace is missing for table ops.tt7.

mysql 

mysql alter table tt7 import tablespace;

Query OK, 0 rows affected (0.08 sec)

mysql 

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql

###############################################

################################################

mysql mysql show tables;

+—————-+

| Tables_in_ops2 |

+—————-+

| tt2            |

| tt3            |

| tt7            |

+—————-+

3 rows in set (0.00 sec)

mysql 

mysql use ops

Database changed

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

+—————+

1 row in set (0.00 sec)

mysql 

mysql use ops2;

Database changed

mysql select * from tt7;

+——–+——+

| x      | y    |

+——–+——+

| BBBBBB | NULL |

+——–+——+

1 row in set (0.00 sec)

mysql 

mysql 

mysql insert into tt7 select * from tt3;

Query OK, 3 rows affected (0.00 sec)

Records: 3  Duplicates: 0  Warnings: 0

mysql insert into tt7 select * from tt3;

Query OK, 3 rows affected (0.00 sec)

Records: 3  Duplicates: 0  Warnings: 0

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql 

mysql commit;

Query OK, 0 rows affected (0.00 sec)

mysql 

mysql exit

Bye

[root@qaserver120 pkg]# cd /data/mysql/ops2

[root@qaserver120 ops2]# ll

total 240

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt3.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:36 tt7.ibd

[root@qaserver120 ops2]# 

[root@qaserver120 ops2]# 

[root@qaserver120 ops2]# 

[root@qaserver120 ops2]# mysql -u’root’  -p’fgxkB9;Zq40^MFQUi$PJ’        -A

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 56

Server version: 8.0.18 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 use ops2

Database changed

mysql 

mysql flush tables tt7   for export; 

Query OK, 0 rows affected (0.00 sec)

mysql show tables;

+—————-+

| Tables_in_ops2 |

+—————-+

| tt2            |

| tt3            |

| tt7            |

+—————-+

3 rows in set (0.01 sec)

mysql exit

Bye

[root@qaserver120 ops2]# ll

total 240

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt3.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:36 tt7.ibd

[root@qaserver120 ops2]# ll

total 240

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt3.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:36 tt7.ibd

[root@qaserver120 ops2]# pwd

/data/mysql/ops2

[root@qaserver120 ops2]# cd  cd /data/mysql 

-bash: cd: cd: No such file or directory

[root@qaserver120 ops2]#  cd /data/mysql/ops2

[root@qaserver120 ops2]# ll

total 240

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:17 tt3.ibd

-rw-r—– 1 mysql mysql 114688 Dec  2 21:36 tt7.ibd

[root@qaserver120 ops2]# ll -al

total 244

drwxr-x—  2 mysql mysql     51 Dec  2 21:38 .

drwxr-xr-x 12 mysql mysql   4096 Dec  2 21:17 ..

-rw-r—–  1 mysql mysql 114688 Dec  2 21:17 tt2.ibd

-rw-r—–  1 mysql mysql 114688 Dec  2 21:17 tt3.ibd

-rw-r—–  1 mysql mysql 114688 Dec  2 21:36 tt7.ibd

[root@qaserver120 ops2]# pwd

/data/mysql/ops2

[root@qaserver120 ops2]# mysql -u’root’  -p’fgxkB9;Zq40^MFQUi$PJ’        -A

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 57

Server version: 8.0.18 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 use ops2

Database changed

mysql show tables;

+—————-+

| Tables_in_ops2 |

+—————-+

| tt2            |

| tt3            |

| tt7            |

+—————-+

3 rows in set (0.00 sec)

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql flush tables tt7   for export; 

Query OK, 0 rows affected (0.00 sec)

mysql use ops

Database changed

mysql ll

    – ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ll’ at line 1

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

+—————+

1 row in set (0.00 sec)

mysql 

mysql 

mysql alter table tt7 import tablespace; 

ERROR 1100 (HY000): Table ‘tt7’ was not locked with LOCK TABLES

mysql 

mysql 

mysql use ops2

Database changed

mysql show tables;

+—————-+

| Tables_in_ops2 |

+—————-+

| tt2            |

| tt3            |

| tt7            |

+—————-+

3 rows in set (0.00 sec)

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql unlock tables;

Query OK, 0 rows affected (0.00 sec)

mysql show create table  tt7;

+——-+——————————————————————————————————————————————————————————————————+

| Table | Create Table                                                                                                                                                                                         |

+——-+——————————————————————————————————————————————————————————————————+

| tt7   | CREATE TABLE `tt7` (

  `x` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL,

  `y` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs |

+——-+——————————————————————————————————————————————————————————————————+

1 row in set (0.00 sec)

mysql use ops

Database changed

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

+—————+

1 row in set (0.01 sec)

mysql  CREATE TABLE `tt7` (

    –   `x` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL,

    –   `y` int(11) DEFAULT NULL

    – ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs ;

Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql 

mysql 

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

| tt7           |

+—————+

2 rows in set (0.00 sec)

mysql select * from tt7;

Empty set (0.00 sec)

mysql 

mysql alter table tt7  discard tablesapce; 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘tablesapce’ at line 1

mysql alter table tt7  discard tablespace;

Query OK, 0 rows affected (0.03 sec)

mysql 

mysql 

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

| tt7           |

+—————+

2 rows in set (0.00 sec)

mysql select * from tt7;

ERROR 1814 (HY000): Tablespace has been discarded for table ‘tt7’

mysql 

mysql 

mysql 

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

| tt7           |

+—————+

2 rows in set (0.00 sec)

mysql select * from tt7;

ERROR 1814 (HY000): Tablespace has been discarded for table ‘tt7’

mysql 

mysql 

mysql alter table tt7 import tablespace; 

ERROR 1812 (HY000): Tablespace is missing for table `ops`.`tt7`.

mysql 

mysql 

mysql 

mysql alter table tt7 import tablespace;

Query OK, 0 rows affected (0.08 sec)

mysql 

mysql 

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql SELECT  * FROM   ops2.tt7    ;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql SELECT  * FROM   ops.tt7    ;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql 

mysql 

mysql 

mysql unlock tables; 

Query OK, 0 rows affected (0.00 sec)

mysql unlock tables; 

Query OK, 0 rows affected (0.00 sec)

mysql use ops

Database changed

mysql show tables;

+—————+

| Tables_in_ops |

+—————+

| tt2           |

| tt7           |

+—————+

2 rows in set (0.00 sec)

mysql 

mysql 

mysql 

mysql use ops2;

Database changed

mysql 

mysql 

mysql show tables;

+—————-+

| Tables_in_ops2 |

+—————-+

| tt2            |

| tt3            |

| tt7            |

+—————-+

3 rows in set (0.01 sec)

mysql 

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql 

mysql use ops;

Database changed

mysql 

mysql 

mysql select * from tt7;

+————–+——+

| x            | y    |

+————–+——+

| BBBBBB       | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

| AAAAAA       | NULL |

| BBBBBB       | NULL |

| 555555555555 | NULL |

+————–+——+

7 rows in set (0.00 sec)

mysql資料庫8g這麼大怎麼遷移好

1.使用MSSQL2MYSQL 開源軟體幫助你遷移;

2.利用MSSQL軟體提供的跨異構數據源的工具,直接遠程數據寫入到MySQL中;

3.數據到導出為特殊分隔符的文本數據,再使用LOAD DATA 命令載入;

mysql5.1的資料庫如何遷移至mysql5.7?

安全的辦法是在舊環境導出表數、在新環境建立資料庫後導入表,可以使用SQL或者TXT為中間文件。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/233989.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-11 17:12
下一篇 2024-12-11 17:12

相關推薦

  • 如何修改mysql的埠號

    本文將介紹如何修改mysql的埠號,方便開發者根據實際需求配置對應埠號。 一、為什麼需要修改mysql埠號 默認情況下,mysql使用的埠號是3306。在某些情況下,我們需…

    編程 2025-04-29
  • Python讀取CSV數據畫散點圖

    本文將從以下方面詳細闡述Python讀取CSV文件並畫出散點圖的方法: 一、CSV文件介紹 CSV(Comma-Separated Values)即逗號分隔值,是一種存儲表格數據的…

    編程 2025-04-29
  • Python 常用資料庫有哪些?

    在Python編程中,資料庫是不可或缺的一部分。隨著互聯網應用的不斷擴大,處理海量數據已成為一種趨勢。Python有許多成熟的資料庫管理系統,接下來我們將從多個方面介紹Python…

    編程 2025-04-29
  • Python中讀入csv文件數據的方法用法介紹

    csv是一種常見的數據格式,通常用於存儲小型數據集。Python作為一種廣泛流行的編程語言,內置了許多操作csv文件的庫。本文將從多個方面詳細介紹Python讀入csv文件的方法。…

    編程 2025-04-29
  • 如何用Python統計列表中各數據的方差和標準差

    本文將從多個方面闡述如何使用Python統計列表中各數據的方差和標準差, 並給出詳細的代碼示例。 一、什麼是方差和標準差 方差是衡量數據變異程度的統計指標,它是每個數據值和該數據值…

    編程 2025-04-29
  • openeuler安裝資料庫方案

    本文將介紹在openeuler操作系統中安裝資料庫的方案,並提供代碼示例。 一、安裝MariaDB 下面介紹如何在openeuler中安裝MariaDB。 1、更新軟體源 sudo…

    編程 2025-04-29
  • Python多線程讀取數據

    本文將詳細介紹多線程讀取數據在Python中的實現方法以及相關知識點。 一、線程和多線程 線程是操作系統調度的最小單位。單線程程序只有一個線程,按照程序從上到下的順序逐行執行。而多…

    編程 2025-04-29
  • Python爬取公交數據

    本文將從以下幾個方面詳細闡述python爬取公交數據的方法: 一、準備工作 1、安裝相關庫 import requests from bs4 import BeautifulSou…

    編程 2025-04-29
  • Python兩張表數據匹配

    本篇文章將詳細闡述如何使用Python將兩張表格中的數據匹配。以下是具體的解決方法。 一、數據匹配的概念 在生活和工作中,我們常常需要對多組數據進行比對和匹配。在數據量較小的情況下…

    編程 2025-04-29
  • Python數據標準差標準化

    本文將為大家詳細講述Python中的數據標準差標準化,以及涉及到的相關知識。 一、什麼是數據標準差標準化 數據標準差標準化是數據處理中的一種方法,通過對數據進行標準差標準化可以將不…

    編程 2025-04-29

發表回復

登錄後才能評論