diff --git a/mysql-test/suite/plugins/r/mdev_27087.result b/mysql-test/suite/plugins/r/mdev_27087.result deleted file mode 100644 index 9cffceaa4db..00000000000 --- a/mysql-test/suite/plugins/r/mdev_27087.result +++ /dev/null @@ -1,12 +0,0 @@ -show variables like 'sql_error_log%'; -Variable_name Value -sql_error_log_filename sql_errors.log -sql_error_log_rate 1 -sql_error_log_rotate OFF -sql_error_log_rotations 9 -sql_error_log_size_limit 1000000 -sql_error_log_with_db_and_thread_info ON -set global sql_error_log_rate=1; -select * from t_doesnt_exist; -ERROR 42S02: Table 'test.t_doesnt_exist' doesn't exist -THREAD_ID DATABASE_NAME TIME HOSTNAME ERROR 1146: Table 'test.t_doesnt_exist' doesn't exist : select * from t_doesnt_exist diff --git a/mysql-test/suite/plugins/r/sql_error_log_withdbinfo.result b/mysql-test/suite/plugins/r/sql_error_log_withdbinfo.result new file mode 100644 index 00000000000..649d91269b6 --- /dev/null +++ b/mysql-test/suite/plugins/r/sql_error_log_withdbinfo.result @@ -0,0 +1,37 @@ +show variables like 'sql_error_log%'; +Variable_name Value +sql_error_log_filename sql_errors.log +sql_error_log_rate 1 +sql_error_log_rotate OFF +sql_error_log_rotations 9 +sql_error_log_size_limit 1000000 +sql_error_log_with_db_and_thread_info ON +set global sql_error_log_rate=1; +# Trying to set the variable at runtime +SET sql_error_log_with_db_and_thread_info=OFF; +ERROR HY000: Variable 'sql_error_log_with_db_and_thread_info' is a read only variable +# +# Using test database from mtr +# +DROP DATABASE db; +ERROR HY000: Can't drop database 'db'; database doesn't exist +# +# Using no database at all +# +DROP DATABASE test; +DROP DATABASE db; +ERROR HY000: Can't drop database 'db'; database doesn't exist +# +# Using database with name `NULL` +# +CREATE DATABASE `NULL`; +USE `NULL`; +DROP DATABASE db; +ERROR HY000: Can't drop database 'db'; database doesn't exist +THREAD_ID `test` TIME HOSTNAME ERROR 1238: Variable 'sql_error_log_with_db_and_thread_info' is a read only variable : SET sql_error_log_with_db_and_thread_info=OFF +THREAD_ID `test` TIME HOSTNAME ERROR 1008: Can't drop database 'db'; database doesn't exist : DROP DATABASE db +THREAD_ID NULL TIME HOSTNAME ERROR 1008: Can't drop database 'db'; database doesn't exist : DROP DATABASE db +THREAD_ID `NULL` TIME HOSTNAME ERROR 1008: Can't drop database 'db'; database doesn't exist : DROP DATABASE db +DROP DATABASE `NULL`; +# Reset +CREATE DATABASE test; diff --git a/mysql-test/suite/plugins/t/mdev_27087.test b/mysql-test/suite/plugins/t/mdev_27087.test deleted file mode 100644 index ddd677b6681..00000000000 --- a/mysql-test/suite/plugins/t/mdev_27087.test +++ /dev/null @@ -1,18 +0,0 @@ ---source include/not_embedded.inc - -if (!$SQL_ERRLOG_SO) { - skip No SQL_ERROR_LOG plugin; -} - -show variables like 'sql_error_log%'; -set global sql_error_log_rate=1; ---error ER_NO_SUCH_TABLE -select * from t_doesnt_exist; - -let $MYSQLD_DATADIR= `SELECT @@datadir`; ---let SEARCH_FILE= $MYSQLD_DATADIR/sql_errors.log ---let LINES_TO_READ=1 ---replace_regex /[1-9]* test [1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [^E]*/THREAD_ID DATABASE_NAME TIME HOSTNAME / ---source include/read_head.inc - -remove_file $MYSQLD_DATADIR/sql_errors.log; diff --git a/mysql-test/suite/plugins/t/mdev_27087.opt b/mysql-test/suite/plugins/t/sql_error_log_withdbinfo.opt similarity index 62% rename from mysql-test/suite/plugins/t/mdev_27087.opt rename to mysql-test/suite/plugins/t/sql_error_log_withdbinfo.opt index 53c8ec8f812..7d502896977 100644 --- a/mysql-test/suite/plugins/t/mdev_27087.opt +++ b/mysql-test/suite/plugins/t/sql_error_log_withdbinfo.opt @@ -1 +1 @@ ---plugin-load-add=$SQL_ERRLOG_SO --sql-error-log-with-db-and-thread-info=1 +--plugin-load-add=$SQL_ERRLOG_SO --sql-error-log-with-db-and-thread-info=1 --lower_case_table_names=2 diff --git a/mysql-test/suite/plugins/t/sql_error_log_withdbinfo.test b/mysql-test/suite/plugins/t/sql_error_log_withdbinfo.test new file mode 100644 index 00000000000..bddcc14e275 --- /dev/null +++ b/mysql-test/suite/plugins/t/sql_error_log_withdbinfo.test @@ -0,0 +1,49 @@ +--source include/not_embedded.inc + +if (!$SQL_ERRLOG_SO) { + skip No SQL_ERROR_LOG plugin; +} + +show variables like 'sql_error_log%'; +set global sql_error_log_rate=1; + +let $MYSQLD_DATADIR= `SELECT @@datadir`; + +--echo # Trying to set the variable at runtime + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +SET sql_error_log_with_db_and_thread_info=OFF; + +--echo # +--echo # Using test database from mtr +--echo # + +--error ER_DB_DROP_EXISTS +DROP DATABASE db; + +--echo # +--echo # Using no database at all +--echo # + +DROP DATABASE test; +--error ER_DB_DROP_EXISTS +DROP DATABASE db; + +--echo # +--echo # Using database with name `NULL` +--echo # +CREATE DATABASE `NULL`; +USE `NULL`; +--error ER_DB_DROP_EXISTS +DROP DATABASE db; + + +--let SEARCH_FILE= $MYSQLD_DATADIR/sql_errors.log +--let LINES_TO_READ=4 +--replace_regex /[1-9]* `NULL` [1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [^E]*/THREAD_ID `NULL` TIME HOSTNAME / /[1-9]* `test` [1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [^E]*/THREAD_ID `test` TIME HOSTNAME / /[1-9]* NULL [1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [^E]*/THREAD_ID NULL TIME HOSTNAME / +--source include/read_head.inc + +DROP DATABASE `NULL`; + +--echo # Reset +CREATE DATABASE test; diff --git a/plugin/sql_errlog/sql_errlog.c b/plugin/sql_errlog/sql_errlog.c index 619dc2e227e..a3f36fc966e 100644 --- a/plugin/sql_errlog/sql_errlog.c +++ b/plugin/sql_errlog/sql_errlog.c @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -91,6 +92,7 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)), { const struct mysql_event_general *event = (const struct mysql_event_general*)ev; + if (rate && event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR) { @@ -103,12 +105,24 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)), (void) localtime_r(&event_time, &t); if (with_db_and_thread_info) { - logger_printf(logfile, "%llu %s %04d-%02d-%02d %2d:%02d:%02d " + if (event->database.str) + { + logger_printf(logfile, "%llu %`s %04d-%02d-%02d %2d:%02d:%02d " "%s ERROR %d: %s : %s \n", event->general_thread_id, event->database.str, t.tm_year + 1900, - t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, - event->general_user, event->general_error_code, + t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, + t.tm_sec, event->general_user, event->general_error_code, event->general_command, event->general_query); + } + else + { + logger_printf(logfile, "%llu %s %04d-%02d-%02d %2d:%02d:%02d " + "%s ERROR %d: %s : %s \n", + event->general_thread_id, "NULL", t.tm_year + 1900, + t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, + t.tm_sec, event->general_user, event->general_error_code, + event->general_command, event->general_query); + } } else {