MySQL Forums
Forum List  »  MySQL Administrator

Show warnings in batch mode / throw errors instead of warnings
Posted by: James Anderson
Date: November 10, 2011 05:53AM

Hi all,

I am trying to write a bash script that will fetch an export from an FTP server, and then import it into my MySQL database on a regular basis.

It all works fine, apart from the fact that in "batch mode" (i.e. either using the -e flag or piping a script file into the mysql command) there is no visible output.

This means I have no idea if there are any errors, warning or skipped rows.

I.e. - when run inside the mysql shell, it looks like this:

mysql> load data local infile '/tmp/bceu-leads-tempfile' into table boat_emails fields terminated by ',' optionally enclosed by '"' lines terminated by '\n';
Query OK, 1 row affected, 6 warnings (0.03 sec)
Records: 1 Deleted: 0 Skipped: 0 Warnings: 5

but when run in batch mode it looks like this:

$ mysql -e "load data local infile '/tmp/bceu-leads-tempfile' into table boat_emails fields terminated by ',' optionally enclosed by '\"' lines terminated by '\n';" -A -uroot -pmysql jimtest
$

I can turn on "show warnings", but this is not the ideal solution.

What I actually want to do is have mysql throw an ERROR, rather than any warnings, and I can then log them to a file that is monitored by our alerting framework. But I don't see any way to do this either. I tried setting sql_mode to TRADITIONAL or STRICT, but when doing negative testing with a file that has too many input columns I just get a warning:

Row 1 was truncated; it contained more data than there were input columns


I don't want a warning that it truncated the data and therefore inserted erroneous data. I want it to fail.

Any assistance anyone can provide on wither of my problems would be most appreciated.

To summarise:
1) Can I get mysql to output the query summary in batch mode?
2) Can I force mysql to throw an error instead of a warning

Thanks,
James



Edited 2 time(s). Last edit at 11/10/2011 05:54AM by James Anderson.

Options: ReplyQuote


Subject
Written By
Posted
Show warnings in batch mode / throw errors instead of warnings
November 10, 2011 05:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.