why it is not imported. how to skip errors? - mysql

ERROR 1300 (HY000): Invalid utf8mb4 character string: 'ditanlui'
in the file I found two entries (dianli) by column. But when importing, you need to skip the error.
LOAD DATA LOCAL INFILE "0.txt" INTO TABLE table1
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
I import via mysql console
mysql 5.7 version

Related

To export query results from MySQL to CSV using SQL in macOS 12.6

I am trying to export query results from MySQL to CSV using SQL by the following query.
SELECT *
FROM Book
INTO OUTFILE '/Users/<MY_NAME>/Desktop/folder1/folder2/book.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
After executing above SQL query I am getting a following error.
Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
I tried by editing .my.cnf file to secure_file_priv='', But still I am getting same error.
I ran the SHOW VARIABLES LIKE 'secure_file_priv'; query. But, I am getting:
# Variable_name, Value
'secure_file_priv', 'NULL'

mysql error (HY000):file not found (Errcode: 2)

So I'm trying to load my database by loading .txt file (fields terminated by \t). But it keeps sending me this error:
mysql> LOAD DATA LOCAL INFILE "C:\\tvshow.txt" INTO TABLE SERIJA FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';
ERROR 2 (HY000): File 'C:\tvshow.txt' not found (Errcode: 2)
Can somebody help me out?
(I'm using PuTTY on Windows 10)

ERROR 13 (HY000): Can't get stat of '/tmp/file1.csv' (Errcode: 2) while trying to import CSV file into MariaDB

I am trying to import CSV file into MariaDB (version: 5.5.50-MariaDB MariaDB Server), using this command:
LOAD DATA INFILE 'file1.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES (#dummy,col1, col2,col3,#dummy)
SET col4 = "xyz";
I am getting error as:
ERROR 13 (HY000): Can't get stat of '/var/lib/mysql/db_name/file1.csv' (Errcode: 2)
I also tried using LOCAL keyword as per some suggestions on stackoverflow and google search in the above query like:
LOAD DATA LOCAL INFILE 'file1.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES (#dummy,col1, col2,col3,#dummy)
SET col4 = "xyz";
in that case, I get a file not found error:
ERROR 2 (HY000): File 'file1.csv' not found (Errcode: 2)
I have tried moving my source file to /tmp, /root and /var/lib/mysql/db_name directories but am not able to import using any of the above queries.
Could anyone please suggest a solution?
Thanks in advance.
The file needs to be either owned by "mysql", or readable by by "mysql". Do ls -l file1.csv if you need further interpretation.
Also, check the value of local_infile.

MySQL import row count inconsistent on same file and DB

I am trying to load a +75mb csv file with 650k+ rows into a MySQL server on Centos Linux. This is just one example. I've also tried the same with 350mb file and 1.75m rows.
I've tried both of these MySQL import functions via command-line. EACH time I import the same file into an empty table the Row Count is different (inconsistent).
Truncate table.
Import from command-line.
Check row count.
Repeat
Here are my results:
640,568
636,547
644,483
640,961
and on, and on, and on....
I've tried these two different import methods:
mysql -u root -ppassword --execute="USE DBNAME;LOAD DATA INFILE '/home/scripts/extracts/NAMEOFTABLE.CSV' INTO TABLE NAMEOFTABLE FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';" --show-warnings
output is empty, no warnings or errors (I have seen them before so I know it works)
mysqlimport -u root -ppassword --fields-terminated-by=, --local DBNAME /home/scripts/extracts/NAMEOFTABLE.CSV
This will output:
DBNAME.NAMEOFTABLE: Records: 647435 Deleted: 0 Skipped: 0 Warnings: 647435
Which at first is exciting, but then I check the rows in DB and it is only 640,480. :(
I've been at this for days. Thanks for your help.
Try this query to import csv from phpmyadmin or any other mysql client
Before firing query, please make sure that table matching the fields is already created into db.
LOAD DATA LOCAL INFILE '/home/scripts/extracts/NAMEOFTABLE.CSV' INTO TABLE `tbl_csvs`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(comma separated fields name here field1, field2, field3);

MySQL Loading Data Error

LOAD DATA
LOCAL INFILE "file.txt"
REPLACE INTO TABLE file
FIELDS TERMINATED BY '|'
(attribute1, attribute2)
LOAD DATA
LOCAL INFILE "file2.txt"
REPLACE INTO TABLE file2
FIELDS TERMINATED BY '|'
(attribute3, attribute4)
I have a single text file composed of several of these "LOAD DATA" commands. I receive an error message saying line 6, or the start of the 2nd command, is not proper syntax. And if I try to introduce a "lines terminated by '\n'" code, it says it is not allowed with my mysql version.
You should add a ';' at the end of each load statement.
LOAD DATA
LOCAL INFILE "file.txt"
REPLACE INTO TABLE file
FIELDS TERMINATED BY '|'
(attribute1, attribute2);
LOAD DATA
LOCAL INFILE "file2.txt"
REPLACE INTO TABLE file2
FIELDS TERMINATED BY '|'
(attribute3, attribute4);
See also ERROR 1148: The used command is not allowed with this MySQL version
You can specify that as an additional option when setting up your client connection:
mysql -u myuser -p --local-infile somedatabase