ablog

不器用で落着きのない技術者のメモ

LOAD DATA ステートメントで発生したワーニングの内容を表示する

LOAD DATA で "Warnings: 48" のようにワーニングが発生した場合に、その内容を見たい場合は、

% mysql  --local-infile -h aurora01.cluster-******.ap-northeast-1.rds.amazonaws.com -u awsuser -p
mysql> LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE TEST FIELDS TERMINATED BY ',' ENCLOSED BY '"';
Query OK, 34 rows affected, 48 warnings (0.06 sec)
Records: 34  Deleted: 0  Skipped: 0  Warnings: 48

MySQL クライアントで接続時に --show-warnings オプションをつけて接続すると表示される。

% mysql  --local-infile --show-warnings -h aurora01.cluster-******.ap-northeast-1.rds.amazonaws.com -u awsuser -p
mysql> LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE TEST FIELDS TERMINATED BY ',' ENCLOSED BY '"';
Warning (Code 1265): Data truncated for column 'COL1' at row 1
Warning (Code 1262): Row 1 was truncated; it contained more data than there were input columns
Warning (Code 1262): Row 2 was truncated; it contained more data than there were input columns

参考

You should startup mysqld with log-warnings (it should be on by default) and also the max error count

[mysqld]
log-warnings
max-error-count=9999999999
You may have to start the mysql client with
SET SQL_WARNINGS = 1;

This is not mysqld setting, it's a mysql client session setting.

You may want to add show-warnings to mysql client session

mysql -u... -p -hlocalhost --show-warnings
mysql - How do I show warnings when loading data created from mysqldump? - Database Administrators Stack Exchange