Home > Database > Mysql Tutorial > body text

MySQL如何导入csv格式数据文件解决方案

WBOY
Release: 2016-06-07 17:55:09
Original
1301 people have browsed it

本文将详细介绍MySQL如何导入csv格式数据文件并提供详细解决方案,需要了解的朋友可以参考下

给自己做备份的,高手们请忽略。
数据太大,用数据库客户端软件直接导入非常卡,还是直接执行SQL吧。
1、指定文件路径。
2、字段之间以逗号分隔,数据行之间以\r\n分隔(我这里文件是以\n分隔的)。
3、字符串以半角双引号包围,字符串本身的双引号用两个双引号表示。

Sql代码
代码如下:
load data infile 'D:\\top-1m.csv'
into table `site`
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by '\n';

顺带也备份个导出吧。
Sql代码
代码如下:
select * from `site`
into outfile 'D:\\top-1m.csv'
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by '\n';

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!