Export and Import bitsCN.com in MYsql data text format
MYsql data text export and import
I. query the table structure
Mysql> desc province;
+ ----------- + ------------- + ------ + ----- + --------- + ---------------- +
| Field | Type | Null | Key | Default | Extra |
+ ----------- + ------------- + ------ + ----- + --------- + ---------------- +
| Id | int (11) | NO | PRI | NULL | auto_increment |
| Name | varchar (32) | NO | NULL |
| CountryId | int (11) | YES | MUL | NULL |
+ ----------- + ------------- + ------ + ----- + --------- + ---------------- +
The data in the two-dimensional table is exported as a two-dimensional file (.txt)
SQL code
Select id, name, countryId
Into outfile "d:/data_out.txt"
Lines terminated by "/r/n"
From province;
Export result:
1 Beijing 1
2 Shanghai 1
3 Tianjin 1
4 Chongqing 1
5 Heilongjiang 1
6 Jilin 1
7 Liaoning 1
......
III. import text files to the database
SQL code
Load data local infile "d:/data_out.txt"
Into table t_province (id, name );
Import result:
Mysql> select * from t_province;
+ ---- + -------- +
| Id | name |
+ ---- + -------- +
| 1 | Beijing |
| 2 | Shanghai |
| 3 | Tianjin |
| 4 | Chongqing |
| 5 | Heilongjiang |
BitsCN.com