Heim  >  Artikel  >  Datenbank  >  csv文件导入数据库

csv文件导入数据库

WBOY
WBOYOriginal
2016-06-07 15:23:201568Durchsuche

csv文件导入数据库的格式和平时导入其他文件是一样的,都需要使用load data infile 语句,但是最关键的是格式参数: 下面是举例: use ip; load data infile E:/ip-to-country.csv into table `ip-to-country-isp` fields terminated by , optionally enclos

csv文件导入数据库的格式和平时导入其他文件是一样的,都需要使用load data infile 语句,但是最关键的是格式参数:

下面是举例:

use ip;
load data infile 'E:/ip-to-country.csv' into table `ip-to-country-isp` fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';
可以就可以把文件导入至数据库表ip-to-country中。

附ip-to-country的表结构:

CREATE TABLE `ip-to-country-isp` (
  `start` bigint(20) default NULL,
  `end` bigint(20) default NULL,
  `country` varchar(11) default NULL,
  `country2` varchar(11) default NULL,
  `des` varchar(50) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
将表导出为csv格式:
select * from ip-to-country-isp 
into outfile 'E:/ip-to-country-isp.csv' 
fields terminated by ',' optionally enclosed by '"' escaped by '"' 
lines terminated by '\r\n'; 
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:报表标准参数值集Nächster Artikel:摄影技能技巧大全