2007-02-26 11:49:24 +01:00
--
-- The system tables of MySQL Server
--
2007-08-27 13:39:34 +02:00
set sql_mode = ' ' ;
2007-02-26 11:49:24 +01:00
set storage_engine = myisam ;
2007-02-27 11:39:29 +01:00
CREATE TABLE IF NOT EXISTS db ( Host char ( 60 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 16 ) binary DEFAULT ' ' NOT NULL , Select_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Insert_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Update_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Delete_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Drop_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Grant_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , References_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Index_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Alter_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_tmp_table_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Lock_tables_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Show_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Alter_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Execute_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Event_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Trigger_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , PRIMARY KEY Host ( Host , Db , User ) , KEY User ( User ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' Database privileges ' ;
2007-02-26 11:49:24 +01:00
2007-04-12 17:48:28 +02:00
-- Remember for later if db table already existed
set @ had_db_table = @ @ warning_count ! = 0 ;
2007-02-26 11:49:24 +01:00
2007-02-27 11:39:29 +01:00
CREATE TABLE IF NOT EXISTS host ( Host char ( 60 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , Select_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Insert_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Update_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Delete_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Drop_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Grant_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , References_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Index_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Alter_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_tmp_table_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Lock_tables_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Show_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Alter_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Execute_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Trigger_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , PRIMARY KEY Host ( Host , Db ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' Host privileges; Merged with database privileges ' ;
2007-02-26 11:49:24 +01:00
2007-02-27 11:39:29 +01:00
CREATE TABLE IF NOT EXISTS user ( Host char ( 60 ) binary DEFAULT ' ' NOT NULL , User char ( 16 ) binary DEFAULT ' ' NOT NULL , Password char ( 41 ) character set latin1 collate latin1_bin DEFAULT ' ' NOT NULL , Select_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Insert_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Update_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Delete_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Drop_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Reload_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Shutdown_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Process_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , File_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Grant_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , References_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Index_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Alter_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Show_db_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Super_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_tmp_table_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Lock_tables_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Execute_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Repl_slave_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Repl_client_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Show_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Alter_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Create_user_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Event_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , Trigger_priv enum ( ' N ' , ' Y ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , ssl_type enum ( ' ' , ' ANY ' , ' X509 ' , ' SPECIFIED ' ) COLLATE utf8_general_ci DEFAULT ' ' NOT NULL , ssl_cipher BLOB NOT NULL , x509_issuer BLOB NOT NULL , x509_subject BLOB NOT NULL , max_questions int ( 11 ) unsigned DEFAULT 0 NOT NULL , max_updates int ( 11 ) unsigned DEFAULT 0 NOT NULL , max_connections int ( 11 ) unsigned DEFAULT 0 NOT NULL , max_user_connections int ( 11 ) unsigned DEFAULT 0 NOT NULL , PRIMARY KEY Host ( Host , User ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' Users and global privileges ' ;
2007-02-26 11:49:24 +01:00
2007-04-12 17:48:28 +02:00
-- Remember for later if user table already existed
set @ had_user_table = @ @ warning_count ! = 0 ;
2007-02-26 11:49:24 +01:00
CREATE TABLE IF NOT EXISTS func ( name char ( 64 ) binary DEFAULT ' ' NOT NULL , ret tinyint ( 1 ) DEFAULT ' 0 ' NOT NULL , dl char ( 128 ) DEFAULT ' ' NOT NULL , type enum ( ' function ' , ' aggregate ' ) COLLATE utf8_general_ci NOT NULL , PRIMARY KEY ( name ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' User defined functions ' ;
2007-02-27 11:39:29 +01:00
CREATE TABLE IF NOT EXISTS plugin ( name char ( 64 ) binary DEFAULT ' ' NOT NULL , dl char ( 128 ) DEFAULT ' ' NOT NULL , PRIMARY KEY ( name ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' MySQL plugins ' ;
CREATE TABLE IF NOT EXISTS servers ( Server_name char ( 64 ) NOT NULL DEFAULT ' ' , Host char ( 64 ) NOT NULL DEFAULT ' ' , Db char ( 64 ) NOT NULL DEFAULT ' ' , Username char ( 64 ) NOT NULL DEFAULT ' ' , Password char ( 64 ) NOT NULL DEFAULT ' ' , Port INT ( 4 ) NOT NULL DEFAULT ' 0 ' , Socket char ( 64 ) NOT NULL DEFAULT ' ' , Wrapper char ( 64 ) NOT NULL DEFAULT ' ' , Owner char ( 64 ) NOT NULL DEFAULT ' ' , PRIMARY KEY ( Server_name ) ) CHARACTER SET utf8 comment = ' MySQL Foreign Servers table ' ;
CREATE TABLE IF NOT EXISTS tables_priv ( Host char ( 60 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 16 ) binary DEFAULT ' ' NOT NULL , Table_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Grantor char ( 77 ) DEFAULT ' ' NOT NULL , Timestamp timestamp ( 14 ) , Table_priv set ( ' Select ' , ' Insert ' , ' Update ' , ' Delete ' , ' Create ' , ' Drop ' , ' Grant ' , ' References ' , ' Index ' , ' Alter ' , ' Create View ' , ' Show view ' , ' Trigger ' ) COLLATE utf8_general_ci DEFAULT ' ' NOT NULL , Column_priv set ( ' Select ' , ' Insert ' , ' Update ' , ' References ' ) COLLATE utf8_general_ci DEFAULT ' ' NOT NULL , PRIMARY KEY ( Host , Db , User , Table_name ) , KEY Grantor ( Grantor ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' Table privileges ' ;
2007-02-26 11:49:24 +01:00
CREATE TABLE IF NOT EXISTS columns_priv ( Host char ( 60 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 16 ) binary DEFAULT ' ' NOT NULL , Table_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Column_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Timestamp timestamp ( 14 ) , Column_priv set ( ' Select ' , ' Insert ' , ' Update ' , ' References ' ) COLLATE utf8_general_ci DEFAULT ' ' NOT NULL , PRIMARY KEY ( Host , Db , User , Table_name , Column_name ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' Column privileges ' ;
CREATE TABLE IF NOT EXISTS help_topic ( help_topic_id int unsigned not null , name char ( 64 ) not null , help_category_id smallint unsigned not null , description text not null , example text not null , url char ( 128 ) not null , primary key ( help_topic_id ) , unique index ( name ) ) engine = MyISAM CHARACTER SET utf8 comment = ' help topics ' ;
CREATE TABLE IF NOT EXISTS help_category ( help_category_id smallint unsigned not null , name char ( 64 ) not null , parent_category_id smallint unsigned null , url char ( 128 ) not null , primary key ( help_category_id ) , unique index ( name ) ) engine = MyISAM CHARACTER SET utf8 comment = ' help categories ' ;
CREATE TABLE IF NOT EXISTS help_relation ( help_topic_id int unsigned not null references help_topic , help_keyword_id int unsigned not null references help_keyword , primary key ( help_keyword_id , help_topic_id ) ) engine = MyISAM CHARACTER SET utf8 comment = ' keyword-topic relation ' ;
CREATE TABLE IF NOT EXISTS help_keyword ( help_keyword_id int unsigned not null , name char ( 64 ) not null , primary key ( help_keyword_id ) , unique index ( name ) ) engine = MyISAM CHARACTER SET utf8 comment = ' help keywords ' ;
CREATE TABLE IF NOT EXISTS time_zone_name ( Name char ( 64 ) NOT NULL , Time_zone_id int unsigned NOT NULL , PRIMARY KEY Name ( Name ) ) engine = MyISAM CHARACTER SET utf8 comment = ' Time zone names ' ;
CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment , Use_leap_seconds enum ( ' Y ' , ' N ' ) COLLATE utf8_general_ci DEFAULT ' N ' NOT NULL , PRIMARY KEY TzId ( Time_zone_id ) ) engine = MyISAM CHARACTER SET utf8 comment = ' Time zones ' ;
CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL , Transition_time bigint signed NOT NULL , Transition_type_id int unsigned NOT NULL , PRIMARY KEY TzIdTranTime ( Time_zone_id , Transition_time ) ) engine = MyISAM CHARACTER SET utf8 comment = ' Time zone transitions ' ;
CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL , Transition_type_id int unsigned NOT NULL , Offset int signed DEFAULT 0 NOT NULL , Is_DST tinyint unsigned DEFAULT 0 NOT NULL , Abbreviation char ( 8 ) DEFAULT ' ' NOT NULL , PRIMARY KEY TzIdTrTId ( Time_zone_id , Transition_type_id ) ) engine = MyISAM CHARACTER SET utf8 comment = ' Time zone transition types ' ;
CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL , Correction int signed NOT NULL , PRIMARY KEY TranTime ( Transition_time ) ) engine = MyISAM CHARACTER SET utf8 comment = ' Leap seconds information for time zones ' ;
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
CREATE TABLE IF NOT EXISTS proc ( db char ( 64 ) collate utf8_bin DEFAULT ' ' NOT NULL , name char ( 64 ) DEFAULT ' ' NOT NULL , type enum ( ' FUNCTION ' , ' PROCEDURE ' ) NOT NULL , specific_name char ( 64 ) DEFAULT ' ' NOT NULL , language enum ( ' SQL ' ) DEFAULT ' SQL ' NOT NULL , sql_data_access enum ( ' CONTAINS_SQL ' , ' NO_SQL ' , ' READS_SQL_DATA ' , ' MODIFIES_SQL_DATA ' ) DEFAULT ' CONTAINS_SQL ' NOT NULL , is_deterministic enum ( ' YES ' , ' NO ' ) DEFAULT ' NO ' NOT NULL , security_type enum ( ' INVOKER ' , ' DEFINER ' ) DEFAULT ' DEFINER ' NOT NULL , param_list blob NOT NULL , returns char ( 64 ) DEFAULT ' ' NOT NULL , body longblob NOT NULL , definer char ( 77 ) collate utf8_bin DEFAULT ' ' NOT NULL , created timestamp , modified timestamp , sql_mode set ( ' REAL_AS_FLOAT ' , ' PIPES_AS_CONCAT ' , ' ANSI_QUOTES ' , ' IGNORE_SPACE ' , ' NOT_USED ' , ' ONLY_FULL_GROUP_BY ' , ' NO_UNSIGNED_SUBTRACTION ' , ' NO_DIR_IN_CREATE ' , ' POSTGRESQL ' , ' ORACLE ' , ' MSSQL ' , ' DB2 ' , ' MAXDB ' , ' NO_KEY_OPTIONS ' , ' NO_TABLE_OPTIONS ' , ' NO_FIELD_OPTIONS ' , ' MYSQL323 ' , ' MYSQL40 ' , ' ANSI ' , ' NO_AUTO_VALUE_ON_ZERO ' , ' NO_BACKSLASH_ESCAPES ' , ' STRICT_TRANS_TABLES ' , ' STRICT_ALL_TABLES ' , ' NO_ZERO_IN_DATE ' , ' NO_ZERO_DATE ' , ' INVALID_DATES ' , ' ERROR_FOR_DIVISION_BY_ZERO ' , ' TRADITIONAL ' , ' NO_AUTO_CREATE_USER ' , ' HIGH_NOT_PRECEDENCE ' ) DEFAULT ' ' NOT NULL , comment char ( 64 ) collate utf8_bin DEFAULT ' ' NOT NULL , character_set_client char ( 32 ) collate utf8_bin , collation_connection char ( 32 ) collate utf8_bin , db_collation char ( 32 ) collate utf8_bin , body_utf8 longblob , PRIMARY KEY ( db , name , type ) ) engine = MyISAM character set utf8 comment = ' Stored Procedures ' ;
2007-02-26 11:49:24 +01:00
CREATE TABLE IF NOT EXISTS procs_priv ( Host char ( 60 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 16 ) binary DEFAULT ' ' NOT NULL , Routine_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Routine_type enum ( ' FUNCTION ' , ' PROCEDURE ' ) NOT NULL , Grantor char ( 77 ) DEFAULT ' ' NOT NULL , Proc_priv set ( ' Execute ' , ' Alter Routine ' , ' Grant ' ) COLLATE utf8_general_ci DEFAULT ' ' NOT NULL , Timestamp timestamp ( 14 ) , PRIMARY KEY ( Host , Db , User , Routine_name , Routine_type ) , KEY Grantor ( Grantor ) ) engine = MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment = ' Procedure privileges ' ;
2007-07-26 18:05:01 +02:00
-- Create general_log if CSV is enabled.
2007-02-27 11:39:29 +01:00
2007-08-27 13:16:39 +02:00
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 ' ) ;
2007-04-18 16:23:19 +02:00
2007-07-26 18:05:01 +02:00
PREPARE stmt FROM @ str ;
EXECUTE stmt ;
DROP PREPARE stmt ;
-- Create slow_log if CSV is enabled.
2007-08-27 13:16:39 +02:00
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 ' ) ;
2007-07-26 18:05:01 +02:00
PREPARE stmt FROM @ str ;
EXECUTE stmt ;
DROP PREPARE stmt ;
2007-02-27 11:39:29 +01:00
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
CREATE TABLE IF NOT EXISTS event ( db char ( 64 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default ' ' , name char ( 64 ) CHARACTER SET utf8 NOT NULL default ' ' , body longblob NOT NULL , definer char ( 77 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default ' ' , execute_at DATETIME default NULL , interval_value int ( 11 ) default NULL , interval_field ENUM ( ' YEAR ' , ' QUARTER ' , ' MONTH ' , ' DAY ' , ' HOUR ' , ' MINUTE ' , ' WEEK ' , ' SECOND ' , ' MICROSECOND ' , ' YEAR_MONTH ' , ' DAY_HOUR ' , ' DAY_MINUTE ' , ' DAY_SECOND ' , ' HOUR_MINUTE ' , ' HOUR_SECOND ' , ' MINUTE_SECOND ' , ' DAY_MICROSECOND ' , ' HOUR_MICROSECOND ' , ' MINUTE_MICROSECOND ' , ' SECOND_MICROSECOND ' ) default NULL , created TIMESTAMP NOT NULL , modified TIMESTAMP NOT NULL , last_executed DATETIME default NULL , starts DATETIME default NULL , ends DATETIME default NULL , status ENUM ( ' ENABLED ' , ' DISABLED ' , ' SLAVESIDE_DISABLED ' ) NOT NULL default ' ENABLED ' , on_completion ENUM ( ' DROP ' , ' PRESERVE ' ) NOT NULL default ' DROP ' , sql_mode set ( ' REAL_AS_FLOAT ' , ' PIPES_AS_CONCAT ' , ' ANSI_QUOTES ' , ' IGNORE_SPACE ' , ' NOT_USED ' , ' ONLY_FULL_GROUP_BY ' , ' NO_UNSIGNED_SUBTRACTION ' , ' NO_DIR_IN_CREATE ' , ' POSTGRESQL ' , ' ORACLE ' , ' MSSQL ' , ' DB2 ' , ' MAXDB ' , ' NO_KEY_OPTIONS ' , ' NO_TABLE_OPTIONS ' , ' NO_FIELD_OPTIONS ' , ' MYSQL323 ' , ' MYSQL40 ' , ' ANSI ' , ' NO_AUTO_VALUE_ON_ZERO ' , ' NO_BACKSLASH_ESCAPES ' , ' STRICT_TRANS_TABLES ' , ' STRICT_ALL_TABLES ' , ' NO_ZERO_IN_DATE ' , ' NO_ZERO_DATE ' , ' INVALID_DATES ' , ' ERROR_FOR_DIVISION_BY_ZERO ' , ' TRADITIONAL ' , ' NO_AUTO_CREATE_USER ' , ' HIGH_NOT_PRECEDENCE ' ) DEFAULT ' ' NOT NULL , comment char ( 64 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default ' ' , originator int ( 10 ) NOT NULL , time_zone char ( 64 ) CHARACTER SET latin1 NOT NULL DEFAULT ' SYSTEM ' , character_set_client char ( 32 ) collate utf8_bin , collation_connection char ( 32 ) collate utf8_bin , db_collation char ( 32 ) collate utf8_bin , body_utf8 longblob , PRIMARY KEY ( db , name ) ) ENGINE = MyISAM DEFAULT CHARSET = utf8 COMMENT ' Events ' ;
2007-02-27 11:39:29 +01:00
CREATE TABLE IF NOT EXISTS ndb_binlog_index ( Position BIGINT UNSIGNED NOT NULL , File VARCHAR ( 255 ) NOT NULL , epoch BIGINT UNSIGNED NOT NULL , inserts BIGINT UNSIGNED NOT NULL , updates BIGINT UNSIGNED NOT NULL , deletes BIGINT UNSIGNED NOT NULL , schemaops BIGINT UNSIGNED NOT NULL , PRIMARY KEY ( epoch ) ) ENGINE = MYISAM ;
2007-02-26 11:49:24 +01:00