如何使用Sequel Pro成功将csv导入MySQL

时间:2017-11-09 05:39:57

标签: mysql csv sequelpro

我把头发拉出来。

我有一个csv充满了客户数据,并且在尝试使用Sequel Pro的导入功能将其导入MySQL时遇到了一些错误。

==========

我使用所有默认选项导入,编码为latin1。

表结构是:

CREATE TABLE `sp_personal_info13` (
  `title` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `hours` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `description` varchar(8192) CHARACTER SET utf8 DEFAULT NULL,
  `services` varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
  `in_business_since` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `rating` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `address1` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `address2` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `city` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `state` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `zipcode` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `latitude` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `longitude` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `phone` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
  `fax` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
  `first_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `last_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `email_address` varchar(254) CHARACTER SET utf8 DEFAULT NULL,
  `website` varchar(254) CHARACTER SET utf8 DEFAULT NULL,
  `num_of_reviews` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `sp_categories` varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
  `has_been_initially_contacted` varchar(16) CHARACTER SET utf8 DEFAULT NULL,
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=33298 DEFAULT CHARSET=latin1;

==========

csv有大约47,000个客户条目。这是几个条目的示例(我必须更改数据,因为它是私人客户数据):

Example Customer One    Mon 08.30 AM - 05.00 PM, Tue 08.30 AM - 05.00 PM, Wed 08.30 AM - 05.00 PM, Thu 08.30 AM - 05.00 PM, Fri 08.30 AM - 05.00 PM, Sat Closed, Sun Closed This is just a really long description and in this case it was only one thousand characters long, way shorter than the 8192 this field will allow.  this, is a comma, separated, list of all, different things, about this customer 2006    A   123 Main St #4  VCA 123 Smallville  California  12345   30.12345    -81.889951  4154151515  4157891010  Jan Smith   myemail@gmail.com   www.website.com 67  another,comma,separated,list
Example Customer One    Mon 08.30 AM - 05.00 PM, Tue 08.30 AM - 05.00 PM, Wed 08.30 AM - 05.00 PM, Thu 08.30 AM - 05.00 PM, Fri 08.30 AM - 05.00 PM, Sat Closed, Sun Closed This is just a really long description and in this case it was only one thousand characters long, way shorter than the 8192 this field will allow.  this, is a comma, separated, list of all, different things, about this customer 2006    A   123 Main St #4  VCA 123 Smallville  California  12345   30.12345    -92.937672  4154151515  4157891010  Jan Smith   myemail@gmail.com   www.website.com 67  another,comma,separated,list

这是导入时出现的错误:

"读取文件时出错,因为无法使用您选择的编码(Autodetect - Western(Windows Latin 1))读取该文件。

仅导入了4900行。"

==========

所以我决定只使用它的前3000行,将它保存为新的csv,并尝试调试它,因为它更小。但令人沮丧的是,当我导入该版本时,我完全不同的错误。 : - /这里有错误输出:

[ERROR in row 13] Data too long for column 'in_business_since' at row 1
[ERROR in row 15] Data too long for column 'fax' at row 1
[ERROR in row 20] Data too long for column 'zipcode' at row 1
[ERROR in row 23] Data too long for column 'phone' at row 1
[ERROR in row 269] Data too long for column 'fax' at row 1
[ERROR in row 399] Data too long for column 'phone' at row 1
[ERROR in row 421] Data too long for column 'sp_categories' at row 1
[ERROR in row 846] Data too long for column 'phone' at row 1
[ERROR in row 999] Data too long for column 'sp_categories' at row 1
[ERROR in row 1557] Data too long for column 'sp_categories' at row 1
[ERROR in row 1869] Data too long for column 'zipcode' at row 1
[ERROR in row 1959] Data too long for column 'services' at row 1
[ERROR in row 2359] Data too long for column 'zipcode' at row 1
[ERROR in row 2622] Data too long for column 'sp_categories' at row 1
[ERROR in row 2842] Data too long for column 'sp_categories' at row 1

但是我已经检查过,这些都没有像msg所说的错误太长。

我曾经多年前编写过代码(C,C ++,Java),但对数据库来说还是新手,所以也许我只是粗心大意,但是花了好几天时间而且没有想法。

0 个答案:

没有答案