本文目錄一覽:
- 1、mysql怎麼遷移資料庫
- 2、怎麼將mysql資料庫轉移到另一台電腦上。可以整個mysql安裝目錄一起轉移么
- 3、如何遷移MySQL資料庫
- 4、MySQL8數據遷移大表捷徑【表空間遷移】
- 5、mysql資料庫8g這麼大怎麼遷移好
- 6、mysql5.1的資料庫如何遷移至mysql5.7?
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