如何将文件中的数据加载到MySQL数据库中?

时间:2014-03-05 23:20:05

标签: mysql load-data-infile

我有一个包含大量数据的文件。我正在尝试将数据加载到MySQL数据库中。

我尝试过使用Toad for MySQL但是没有用,因为我在该文件中的文本分布在多行上。 “下面的例子”

现在我尝试使用LOAD DATA LOCAL INFILE将数据加载到名为tt

的表中

但我面临的问题是我收到很多警告。警告是这样的

*************************** 2. row ***************************
  Level: Warning
   Code: 1261
Message: Row 1 doesn't contain data for all columns
*************************** 3. row ***************************
  Level: Warning
   Code: 1261
Message: Row 1 doesn't contain data for all columns

这是我正在使用的查询

LOAD DATA LOCAL INFILE 'c:/ProgramData/MySQL/MySQL Server 5.6/RECORDS.dat' INTO TABLE tt FIELDS ENCLOSED BY '|' TERMINATED BY '|' ESCAPED BY '\\' LINES TERMINATED BY '\n' STARTING BY '006d00000';

有一个“|”每个领域之间的字符。此外,行始终以006d000000开头,我遇到的问题是因为测试有新行。如何在没有问题的情况下加载这些数据?

以下是文件

中的示例数据
006d000000XXXXXXXX||001d000001CCCCCCCC|DN|Test - Standard|Engaged|New Prospect|10000|||100|Blah Blah|No|FedEx Ground||No|||No|012d0000000wxtFFFFFF|2014-02-10 20:00:32.000000|Test Test|2014-02-24 19:01:46.000000|Bl Test|2014-02-20|||||25.00|Direct|Check|||||Inbound Call||||||||Blah|false|false|false|false|false||false|Merchant||||||||English||||
006d000000YYYYYYYY|12345678912345678|001d000001SvqDDDDD|CS|TEST- Derm|Approved|New Prospect|10000|0|211170101|100|Blah|No|FedEx Ground||No|||No|012d0000000wWWWWWWW|2014-01-30 23:10:10.000000|Mike|2014-03-04 10:26:00.000000|Tester|2014-01-31|Blah1 Blah1  Blah1 Blah1  Blah1 Blah1  
Blah1 Blah1  
Blah1 Blah1  

Blah1 Blah1  
||2014-02-01 00:00:00.000000|2014-01-31|0.00|Direct||||Connie wolf corp office  7322444700 ext 6170|||Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  Blah2 Blah2  
Blah2 Blah2  
Blah2 Blah2  

Blah2 Blah2  

||||SSDFHHDR|false|false|false|false|false||false|Location|||2014-02-03|BBAC||Open||English|Yes|1845000||

这是我对tt table的定义

CREATE TABLE `tt` (
 `s_id` varchar(500) DEFAULT NULL,
 `m_id` varchar(50) DEFAULT NULL,
 `sf_id` varchar(50) DEFAULT NULL,
 `p_name` varchar(100) DEFAULT NULL,
 `c_name` varchar(68) DEFAULT NULL,
 `stage` varchar(50) DEFAULT NULL,
 `entype` varchar(50) DEFAULT NULL,
 `en_amount` varchar(50) DEFAULT NULL,
 `vm_sales` varchar(50) DEFAULT NULL,
 `ber` varchar(50) DEFAULT NULL,
 `fansactions` varchar(50) DEFAULT NULL,
 `prolate` varchar(100) DEFAULT NULL,
 `banocess` varchar(50) DEFAULT NULL,
 `shipthod` varchar(50) DEFAULT NULL,
 `averagusage` varchar(50) DEFAULT NULL,
 `banocessing` varchar(50) DEFAULT NULL,
 `banesent` varchar(50) DEFAULT NULL,
 `coid` varchar(50) DEFAULT NULL,
 `siteinoverride` varchar(50) DEFAULT NULL,
 `record_type` varchar(50) DEFAULT NULL,
 `screated_on` varchar(50) DEFAULT NULL,
 `screated_by` varchar(50) DEFAULT NULL,
 `smodified_on` varchar(50) DEFAULT NULL,
 `smodified_by` varchar(52) DEFAULT NULL,
 `submission_date` varchar(50) DEFAULT NULL,
 `inside_notes` varchar(283) DEFAULT NULL,
 `p_number` varchar(50) DEFAULT NULL,
 `approved_on` varchar(56) DEFAULT NULL,
 `en_process_date` varchar(50) DEFAULT NULL,
 `en_fee` varchar(50) DEFAULT NULL,
 `difeature` varchar(50) DEFAULT NULL,
 `payment_type` varchar(50) DEFAULT NULL,
 `closed_on` varchar(56) DEFAULT NULL,
 `reason_for_cancel` varchar(61) DEFAULT NULL,
 `notes_to_t` varchar(500) DEFAULT NULL,
 `offer_code` varchar(50) DEFAULT NULL,
 `reschannel` varchar(50) DEFAULT NULL,
 `p_notes` varchar(1000) DEFAULT NULL,
 `reviewed_td` varchar(50) DEFAULT NULL,
 `review_tdw` varchar(50) DEFAULT NULL,
 `date_rtd` varchar(50) DEFAULT NULL,
 `m_code` varchar(50) DEFAULT NULL,
 `ref_provider` varchar(50) DEFAULT NULL,
 `start_up_kit_sent` varchar(50) DEFAULT NULL,
 `application_source` varchar(50) DEFAULT NULL,
 `did_ancials` varchar(50) DEFAULT NULL,
 `did_iness_license` varchar(50) DEFAULT NULL,
 `did_rk_order` varchar(50) DEFAULT NULL,
 `did_oication` varchar(50) DEFAULT NULL,
 `did_surance` varchar(50) DEFAULT NULL,
 `suppon_url` varchar(50) DEFAULT NULL,
 `interount` varchar(50) DEFAULT NULL,
 `senments_to` varchar(50) DEFAULT NULL,
 `last_activity_date` varchar(50) DEFAULT NULL,
 `f_closed_date` varchar(50) DEFAULT NULL,
 `f_created_date` varchar(50) DEFAULT NULL,
 `f_contact_name` varchar(54) DEFAULT NULL,
 `change_in_program_id` varchar(50) DEFAULT NULL,
 `f_status` varchar(50) DEFAULT NULL,
 `f_close_reason` varchar(50) DEFAULT NULL,
 `language_preference` varchar(50) DEFAULT NULL,
 `do_you_have_a_signature` varchar(50) DEFAULT NULL,
 `p_reference_id` varchar(50) DEFAULT NULL,
 `pricing_schedule` varchar(56) DEFAULT NULL,
 `newline` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

如何修复查询以识别行何时终止以及每个字段何时终止?

1 个答案:

答案 0 :(得分:0)

解决方案是将我的查询更改为

LOAD DATA LOCAL INFILE 'c:/ProgramData/MySQL/MySQL Server 5.6/RECORDS.dat' INTO TABLE tt FIELDS TERMINATED BY '|' ESCAPED BY '\\' LINES TERMINATED BY '|\n' STARTING BY '';