您的位置:首页 > 数据库 > MySQL

Mysql Database 数据迁移

2018-10-10 14:32 453 查看
[root@amb01 ~]# mysql -uroot -pabcd.1234
mysql> show variables like '%secure%';
+------------------+---------------------+
| Variable_name    | Value               |
+------------------+---------------------+
| secure_auth      | ON                  |
| secure_file_priv | /home/mysql/backup/ |
+------------------+---------------------+
2 rows in set (0.00 sec)

mysql> use tpcc1000
Database changed

mysql> select * from customer into outfile '/home/mysql/backup/customer.txt' fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'; 
Query OK, 300000 rows affected (2.47 sec)

mysql> select count(*) from customer;
+----------+
| count(*) |
+----------+
|   300000 |
+----------+
1 row in set (0.11 sec)

mysql> set foreign_key_checks=0;
Query OK, 0 rows affected (0.00 sec)

mysql> truncate table customer;
Query OK, 0 rows affected (0.19 sec)

mysql> select count(*) from customer;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> load data infile '/home/mysql/backup/customer.txt' into table customer fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'; 
Query OK, 300000 rows affected (9.12 sec)
Records: 300000  Deleted: 0  Skipped: 0  Warnings: 0

mysql> set foreign_key_checks=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from customer;
+----------+
| count(*) |
+----------+
|   300000 |
+----------+
1 row in set (0.06 sec)


mysql> set @@global.foreign_key_checks = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@global.foreign_key_checks;
+-----------------------------+
| @@global.foreign_key_checks |
+-----------------------------+
|                           0 |
+-----------------------------+
1 row in set (0.00 sec)

mysql> truncate table customer;
Query OK, 0 rows affected (0.38 sec)

mysql> select count(*) from customer;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

[root@amb01 ~]# mysqlimport -uroot -pabcd.1234 tpcc1000 -d --fields-terminated-by=',' --fields-optionally-enclosed-by='"' --lines-terminated-by='\n' /home/mysql/backup/customer.txt
Warning: Using a password on the command line interface can be insecure.
tpcc1000.customer: Records: 300000  Deleted: 0  Skipped: 0  Warnings: 0

[root@amb01 ~]# mysql -uroot -pabcd.1234
mysql> set @@global.foreign_key_checks = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@global.foreign_key_checks;
+-----------------------------
5b4
+
| @@global.foreign_key_checks |
+-----------------------------+
|                           1 |
+-----------------------------+
1 row in set (0.00 sec)

mysql> use tpcc1000
Database changed

mysql>  select count(*) from customer;
+----------+
| count(*) |
+----------+
|   300000 |
+----------+
1 row in set (0.06 sec)


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql mysqlimport load