I have this file csv:
20170117-00:00:6 3087A6B282A46C 124.191.134.139 2746 256 63628
20170117-00:00:53 330391C9F58B5A 120.18.97.172 2746 257 43077
20170117-00:02:27 3303CD14BD40C8 110.147.131.78 2746 256 63628
20170117-00:02:00 3304B3CD448E4F 189.35.218.62 2746 255 43074
and I am trying to upload it using load data local infile but I obtain only Null value in the time column. Here there is my code (Time is the name of the table column)
LOAD DATA LOCAL INFILE 'path.log'
INTO TABLE Clicks
CHARACTER SET latin1
FIELDS TERMINATED BY '\t'
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
SET Time= STR_TO_DATE(#Time,'%Y%m%d-%H:%i:%s')
;
This is the syntax you should be using:
LOAD DATA LOCAL INFILE 'path.log'
INTO TABLE Clicks
CHARACTER SET latin1
FIELDS TERMINATED BY '\t'
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(#Time, column2, column3, column4, column5) -- read time data into #Time
SET column1 = STR_TO_DATE(#Time, '%Y%m%d-%H:%i:%s') -- then set column1
I think the #Time variable was never being set to anything for each record being read, hence you were getting NULL in the first column.
Try This
LOAD DATA LOCAL INFILE 'path.log'
INTO TABLE Clicks
CHARACTER SET latin1
FIELDS TERMINATED BY '\t'
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
SET TIME= CONCAT(SUBSTRING(#Time,1,4),'-',SUBSTRING(#Time,5,2),'-',SUBSTRING(#Time,7,2),' ',REPLACE(#Time,CONCAT(SUBSTRING_INDEX(#Time, '-',1),'-'),''))
How to set multiple escape letters in MySQL 5.5 . When I set multiple letters ('\",\r,\015\n,\n,\b') in MySQL 5.0.22 it was ok , But in MySQL 5.5.28 is giving error code 'ERROR 1083 (42000): Field separator argument is not what is expected; check the manual'
My Query is as follows ,
select ID,MSISDN,IFNULL(TITLE,''),IFNULL(SECONDARY_TITLE,''),IFNULL (NAME,''),IFNULL(ACTIVATION_DATE,''),IFNULL(CREDIT_EXPIRY_DATE,''),
IFNULL(FIRST_VOICE_CALL_DATE,''),IFNULL(FIRST_SMS_DATE,''),IFNULL(FIRST_MMS_DATE,''),
IFNULL(FIRST_WAP_DATE,''),IFNULL(FIRST_TOPUP_DATE,''),IFNULL(TOTAL_USAGE,''),
IFNULL(TOTAL_TOPUP_AMOUNT,''),IFNULL(TOTAL_TOPUP_COUNT,''),IFNULL(LAST_TOPUP_DATE,''),
IFNULL(ACCOUNT_BALANCE,''),IFNULL(TARIFF_PLAN,''),IFNULL(DATE_OF_BIRTH,''),IFNULL(ADDRESS,''),
IFNULL(COUNTRY,''),IFNULL(CITY,''),IFNULL(POSTCODE,''),IFNULL(IC_NUMBER,''),
GENDER,IFNULL(FIXED_LINE_PHONE,''),IFNULL(EMAIL,''),IFNULL(PROFESSION,''),
IFNULL(EMPLOYER_NAME,''),IFNULL(EMPLOYER_ADDRESS,''),IFNULL(EMPLOYER_PHONE_NUMBER,''),
IFNULL(EMPLOYER_FAX_NUMBER,''),IFNULL(SIM_STATE,''),
IFNULL(ADDITIONAL_INFORMATION,'') INTO OUTFILE '/tmp/SUBSCRIBER_PROFILE.txt'
FIELDS ESCAPED BY '\",\\r,\\015\n,\\n,\\b' TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM SUBSCRIBER_PROFILE;
But When I set only one letter in 'escape by' option, it works
Please help me to solve this issue .
Thanks ,
Dhanushka
The escape character in your case should just be "\" because you're using \ to escape the character. It isn't asking for a list of sequences that you're going to escape, just the character that lets it know that it is being escaped, in this case the \.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Working with MySQL 5.0.21
mysql> select ID,MSISDN,IFNULL(TITLE,''),IFNULL(SECONDARY_TITLE,''),IFNULL(NAME,''),IFNULL(ACTIVATION_DATE,''),IFNULL(CREDIT_EXPIRY_DATE,''),
-> IFNULL(FIRST_VOICE_CALL_DATE,'') ,IFNULL(FIRST_SMS_DATE,''),IFNULL(FIRST_MMS_DATE,''),IFNULL(FIRST_WAP_DATE,''),
-> IFNULL(FIRST_TOPUP_DATE,''),IFNULL(TOTAL_USAGE,''),IFNULL(TOTAL_TOPUP_AMOUNT,''),IFNULL(TOTAL_TOPUP_COUNT,''),
-> IFNULL(LAST_TOPUP_DATE,''),IFNULL(ACCOUNT_BALANCE,''),IFNULL(TARIFF_PLAN,''), IFNULL(DATE_OF_BIRTH,''),IFNULL(ADDRESS,''),
-> IFNULL(COUNTRY,''),IFNULL(CITY,''),IFNULL(POSTCODE,''),IFNULL(IC_NUMBER,''), GENDER,IFNULL(FIXED_LINE_PHONE,''),IFNULL(EMAIL,''),
-> IFNULL(PROFESSION,''),IFNULL(EMPLOYER_NAME,''),IFNULL(EMPLOYER_ADDRESS,''), IFNULL(EMPLOYER_PHONE_NUMBER,''),
-> IFNULL(EMPLOYER_FAX_NUMBER,''),IFNULL(SIM_STATE,''),IFNULL(ADDITIONAL_INFORMATION,'') INTO OUTFILE '/tmp/SUBSCRIBER_PROFILE.txt'
-> ***FIELDS ESCAPED BY '\",\\r,\\015\n,\\n,\\b'*** TERMINATED BY '|' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM SUBSCRIBER_PROFILE;
*Query OK, 345812 rows affected (7.77 sec*)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Not working with MySQL 5.5.28
mysql> select ID,MSISDN,IFNULL(TITLE,''),IFNULL(SECONDARY_TITLE,''),IFNULL(NAME,''),IFNULL(ACTIVATION_DATE,''),IFNULL(CREDIT_EXPIRY_DATE,''),
-> IFNULL(FIRST_VOICE_CALL_DATE,'') ,IFNULL(FIRST_SMS_DATE,''),IFNULL(FIRST_MMS_DATE,''),IFNULL(FIRST_WAP_DATE,''),
-> IFNULL(FIRST_TOPUP_DATE,''),IFNULL(TOTAL_USAGE,''),IFNULL(TOTAL_TOPUP_AMOUNT,''),IFNULL(TOTAL_TOPUP_COUNT,''),
-> IFNULL(LAST_TOPUP_DATE,''),IFNULL(ACCOUNT_BALANCE,''),IFNULL(TARIFF_PLAN,''),IFNULL(DATE_OF_BIRTH,''),IFNULL(ADDRESS,''),
-> IFNULL(COUNTRY,''),IFNULL(CITY,''),IFNULL(POSTCODE,''),IFNULL(IC_NUMBER,''),GENDER,IFNULL(FIXED_LINE_PHONE,''),IFNULL(EMAIL,''),
-> IFNULL(PROFESSION,''),IFNULL(EMPLOYER_NAME,''),IFNULL(EMPLOYER_ADDRESS,''),IFNULL(EMPLOYER_PHONE_NUMBER,''),
-> IFNULL(EMPLOYER_FAX_NUMBER,''),IFNULL(SIM_STATE,''),IFNULL(ADDITIONAL_INFORMATION,'') INTO OUTFILE '/tmp/SUBSCRIBER_PROFILE.txt'
-> **FIELDS ESCAPED BY '\",\\r,\\015\n,\\n,\\b'** TERMINATED BY '|' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM SUBSCRIBER_PROFILE;
*ERROR 1083 (42000): Field separator argument is not what is expected; check the manual*