The problem is a simple one. When I execute the following I get different results depending on whether I run it from the MySQL console and from inside a Python Script using MySQLdb:
LOAD DATA LOCAL INFILE '/tmp/source.csv' INTO TABLE test
FIELDS TERMINATED BY '|'
IGNORE 1 LINES;
Console gives the following results:
Python (via .info()) returns the following:
So in summary, same source file, same SQL request, different results.
From the console I can 'SHOW WARNINGS' an get a better handle on which records are causing the problems and why but from Python I can't idenitify how to do this or more importantly what the cause of the problem could be.
Any suggestions?
After loading the data, execute
SELECT @@warning_count;
check if greater than 0. If it is than execute
SHOW WARNINGS;
and dump the result (returns 3 columns: Level, Code, Message) or throw an exception. You can execute both statements exactly like every other select * from ... query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.