I have found various things that say that you can log warnings to the MySQL error log, but I have not been able to actually make it happen.

I do have the error log working, and MySQL prints stuff to it on startup and shutdown and occasionally at other times, but if I e.g. SELECT CAST('123' AS DATE); and then SHOW WARNINGS; I can see the warning, but it does not show up in any logs.

I've also tried enabling the general log and the slow query log, but these don't show the warnings either.

I've tried with log_warnings = 1 and log_warnings = 2, but still no warnings are logged.

What am I doing wrong?

mysql> show variables like '%error%';
+--------------------+--------------------------+
| Variable_name      | Value                    |
+--------------------+--------------------------+
| error_count        | 0                        |
| log_error          | /var/log/mysql/mysql.err |
| max_connect_errors | 10                       |
| max_error_count    | 1024                     |
| slave_skip_errors  | OFF                      |
+--------------------+--------------------------+

mysql> show variables like '%warn%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_warnings  | 1     |
| sql_warnings  | OFF   |
| warning_count | 0     |
+---------------+-------+
3 rows in set (0.06 sec)

mysql> show variables like '%log%';
+-----------------------------------------+-------------------------------+
| Variable_name                           | Value                         |
+-----------------------------------------+-------------------------------+
...
| general_log                             | ON                            |
| general_log_file                        | /var/log/mysql/general.log    |
...
| log                                     | ON                            |
...
| log_error                               | /var/log/mysql/mysql.err      |
| log_output                              | FILE                          |
| log_queries_not_using_indexes           | ON                            |
...
| log_warnings                            | 1                             |
...
| slow_query_log                          | ON                            |
| slow_query_log_file                     | /var/log/mysql/mysql-slow.log |
...
+-----------------------------------------+-------------------------------+

Edit:

mysql> show global status like 'Aborted%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Aborted_clients  | 24    |
| Aborted_connects | 15    |
+------------------+-------+
2 rows in set (0.08 sec)

Edit:

Clarification: I do get [Warning] Aborted connection 1 to db... and [Warning] Access denied for user... messages logged, but not the warnings that you can see via SHOW WARNINGS after e.g. inserting something or running LOAD DATA INFILE... which is what I'm looking for.

link|improve this question
feedback

2 Answers

Check your count of Aborted Clients and Aborted Connects

SHOW GLOBAL STATUS LIKE 'Aborted%';

If these numbers surpassed 1024, this is probably why warnings past that number won't post in any log.

Try adding this to /etc/my.cnf

warning_count=65535
max_error_count=65535
sql_warnings=1

Restart mysql (warning_count is a readonly variable)

Click here for the description of the following variables:
warning_count
max_error_count
sql_warnings

link|improve this answer
Thanks for the answer, but as you and the docs say, warning_count is readonly, so you can't set it. Also, setting sql_warnings made no difference. The manual is not very clear on whether it's relevant, especially if I want warnings from things other than single-row inserts too. I have edited the question to show that the number of aborted connections is much lower than the max_error_count. – Wodin Feb 15 '11 at 0:19
do you get a warning like Row 688 doesn't contain data for all columns logged to your error log if you LOAD DATA INFILE... and there are too few fields in the file, or Data truncated for column 'xxx' at row 2752 if there is something wrong with one of the rows etc? – Wodin Feb 15 '11 at 6:43
There may be extra delimiters on Line 688. As for line 2752, one of the columns in the data file is is too big for the corresponding column in the table. Even worse, the delimiter you have for LOAD DATA INFILE is probably within the input file as valid data anywhere between line 688 and line 2752. You should probably use Perl and ascertain the number of delimiters you have per line. The number of field delimiters should be identicial. Example: A table with 8 columns can be loaded with 7 field delimiters. Any line with more that 7 needs extra delimiters escaped properly before loading. – RolandoMySQLDBA Feb 15 '11 at 16:49
yes thanks. I know what the warnings mean. The particular warnings are not what I am asking about. The point I am trying to make is that I want to log the warnings somewhere instead of having to SHOW WARNINGS and possibly not have all of them shown because of a too small max_error_count etc. So, to repeat the question from my previous comment, do you get warnings like the above logged to your error log if you load a file with problems like you describe? – Wodin Feb 16 '11 at 7:20
feedback
up vote 0 down vote accepted

I've come to the conclusion that this is not possible. MySQL does not log these warnings to the error log. Only things like e.g. authentication failures, aborted connections, etc.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.