mysql character set encoding in older version - mysql

I am currently trying to run query on old mysql database version 4.x.xx
as
select "something"
INTO OUTFILE '/var/migration/xxx.tsv'
CHARACTER SET utf8
FIELDS ENCLOSED BY '"' TERMINATED BY '\t' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';
but I think UTF8 encoding is not supported. can anyone suggest the way in which i can run this query and get data in utf8 encoding.

According to the MYSQL 4.1 documentation UTF8 is supported. Try this.
mysql_query("set names 'utf8'");
$sql = 'SELECT `something`
INTO OUTFILE '/var/migration/xxx.tsv'
FIELDS ENCLOSED BY '"' TERMINATED BY '\t' ESCAPED BY '"'
LINES TERMINATED BY '\r\n'';
mysql_query($sql);

Related

LINES TERMINATED BY '\n' not working when store mysl result in txt file

When I try to store mysql result in txt file lines terminated is not working
select * from users INTO OUTFILE '/var/lib/mysql-
files/users.txt'
FIELDS TERMINATED BY '|'
ENCLOSED BY '"'
LINES TERMINATED BY '\n';---> not working
the result are all in one line
"1"|"John#test.com"|"20"|"John"|"test"/"2"|"omar#test.com"|"21"|"Omar"|"test2""3"|"Mytest#test.com"|"30"|"Mytest"|"test3"

How to convert string to date time format Mysql

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),'-'),''))

MYSQL command string being cut

i have this code on my program
strSQL = "load data local infile 'C:/csv.csv' replace into table student_records fields terminated by ',' enclosed by '"' lines terminated by '\r\n'"
but the string it considers is only "load data local infile 'C:/csv.csv' replace into table student_records fields terminated by ',' enclosed by '"
and this is considered a comment' lines terminated by '\r\n'"
the string is being terminated by the double quote while it is still part of my mysql command.
can you give me another way around on how to do this?
i'm trying to automate the updating of data in my table.
Try escaping double quotes with "\" character:
strSQL = "load data local infile 'C:/csv.csv' replace into table student_records fields terminated by ',' enclosed by '\"' lines terminated by '\r\n'"

How to set multiple escape letters in mysql 5.5

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*

Filter and export mysql data by script

SELECT siirMisralari_txt
INTO OUTFILE 'C:/Users/Nikel/Desktop/mIRC_02/siir_07.txt'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '$crlf'
FROM `siirler`
WHERE `siirAdi_txt`
LIKE '%Ağustos Şiiri%'
this creates an empty file. why?