Frage

Hi here is my load statement:

load data local infile 'C:/GeoIPCountryWhois.csv' into table geolocation fields terminated by ','
  enclosed by '"'
  lines terminated by '\n';


30 row(s) affected, 1 warning(s):
1265 Data truncated for column 'cn' at row 30
Records: 30  Deleted: 0  Skipped: 0  Warnings: 1



CREATE TABLE `geolocation` (
  `start_ip` char(15) NOT NULL,
  `end_ip` char(15) NOT NULL,
  `start` int(10) unsigned NOT NULL,
  `end` int(10) unsigned NOT NULL,
  `cc` char(2) NOT NULL,
  `cn` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8

I found that the problem is most likely the line below because of the comma in Korea it things that a new field starts.

1.11.0.0,1.11.255.255,17498112,17563647,KR,"Korea, Republic of"

I can remove all the commas but can I change the load statement somehow?

War es hilfreich?

Lösung 2

You should use OPTIONALLY ENCLOSED BY instead of ENCLOSED BY.

http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Adding OPTIONALLY to the statement allows your CSV to be in its current form. Without the OPTIONALLY keyword, it is expected that every value will have quotations around it.

Andere Tipps

My data in mysql is ok, right now. what I change:

in file GeoIPCountryWhois - i used in excel CTRL+H to remove "," from names like "Korea, Republic of" --> "Republic of Korea". and also i removed all "

i have to change in mysql

start bigint(10) unsigned NOT NULL, end bigint(10) unsigned NOT NULL, because was problem from "128.0.0.0" in tables "start" and "end" (this same max int size to end of this tables - duplicates)

importing csv from phpmyadmin : (if you need translate, tell me..)

enter image description here

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top