Home > Database > Mysql Tutorial > body text

MYsql数据文本形式导出与导入_MySQL

WBOY
Release: 2016-06-01 13:32:30
Original
944 people have browsed it

bitsCN.com

MYsql数据文本形式导出与导入

 

一、查询表结构

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    |                |

+-----------+-------------+------+-----+---------+----------------+

二、表中数据导出为文本文件(.txt)

Sql代码  

select id,name,countryId  

into outfile"d:/data_out.txt"  

lines terminated by "/r/n"  

from province;  

 导出结果:

1    北京    1

2    上海    1

3    天津    1

4    重庆    1

5    黑龙江    1

6    吉林    1

7    辽宁    1

……

三、文本文件导入数据库

Sql代码  

load data local infile "d:/data_out.txt"  

into table t_province(id,name);  

 导入结果:

mysql> select * from t_province;

+----+--------+

| id | name   |

+----+--------+

|  1 | 北京   |

|  2 | 上海   |

|  3 | 天津   |

|  4 | 重庆   |

|  5 | 黑龙江 |

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template