Bug #31586 mysql_fix_privilege_tables.sql fails in ANSI mode
Submitted: 14 Oct 2007 9:34 Modified: 17 Nov 2007 12:58
Reporter: Hubert Roksor Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.22 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: Contribution

[14 Oct 2007 9:34] Hubert Roksor
Description:
mysql_fix_privilege_tables.sql fails in ANSI mode because some values are enclosed in double-quotes instead of single-quotes. Error messages are:

ERROR 1064 (42000) at line 70: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"General log"' at line 1
ERROR 1243 (HY000) at line 71: Unknown prepared statement handler (stmt) given to EXECUTE
ERROR 1243 (HY000) at line 72: Unknown prepared statement handler (stmt) given to DEALLOCATE PREPARE
ERROR 1064 (42000) at line 78: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"Slow log"' at line 1
ERROR 1243 (HY000) at line 79: Unknown prepared statement handler (stmt) given to EXECUTE
ERROR 1243 (HY000) at line 80: Unknown prepared statement handler (stmt) given to DEALLOCATE PREPARE

How to repeat:
Set the sql_mode to include 'ANSI' then execute mysql_fix_privilege_tables.sql

Suggested fix:
Replace

SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT, thread_id INTEGER, server_id INTEGER, command_type VARCHAR(64), argument MEDIUMTEXT) engine=CSV CHARACTER SET utf8 comment="General log"', 'SET @dummy = 0');

with

SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT, thread_id INTEGER, server_id INTEGER, command_type VARCHAR(64), argument MEDIUMTEXT) engine=CSV CHARACTER SET utf8 comment=\'General log\'', 'SET @dummy = 0');

Replace

SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME NOT NULL, lock_time TIME NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512), last_insert_id INTEGER, insert_id INTEGER, server_id INTEGER, sql_text MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0');

with

SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME NOT NULL, lock_time TIME NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512), last_insert_id INTEGER, insert_id INTEGER, server_id INTEGER, sql_text MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment=\'Slow log\'', 'SET @dummy = 0');
[14 Oct 2007 9:35] Hubert Roksor
I forgot to add that you need to have the CSV engine enabled in order to reproduce this bug.
[15 Oct 2007 5:30] Valeriy Kravchuk
Thank you for a bug report. Verified just as described.
[17 Nov 2007 12:58] Gleb Shchepa
This bug is a duplicate of bug #28401.

Bugfix for bug #28401 always sets sql_mode to '' at the beginning of scripts/mysql_system_tables.sql (and of generated mysql_fix_privilege_tables.sql file too).