MDEV-14637: Fix hang due to persistent statistics
Similar to the tables SYS_FOREIGN and SYS_FOREIGN_COLS,
the tables mysql.innodb_table_stats and mysql.innodb_index_stats
are updated by the InnoDB internal SQL parser, which fails to
enforce the size limits of the data. Due to this, it is possible
for InnoDB to hang when there are persistent statistics defined on
partitioned tables where the total length of table name,
partition name and subpartition name exceeds the incorrectly
defined limit VARCHAR(64). That column should have been defined
as VARCHAR(199).
btr_node_ptr_max_size(): Interpret the VARCHAR(64) as VARCHAR(199),
to prevent a hang in the case that the upgrade script has not been
run.
dict_table_schema_check(): Ignore difference in the length of the
table_name column.
ha_innobase::max_supported_key_length(): For innodb_page_size=4k,
return a larger value so that the table mysql.innodb_index_stats
can be created. This could allow "impossible" tables to be created,
such that it is not possible to insert anything into a secondary
index when both the secondary key and the primary key are long,
but this is the easiest and most consistent way. The Oracle fix
would only ignore the maximum length violation for the two
statistics tables.
os_file_get_status_posix(), os_file_get_status_win32(): Handle
ENAMETOOLONG as well.
This patch is based on the following change in MySQL 5.7.23.
Not all changes were applied, and our variant allows persistent
statistics to work without hangs even if the table definitions
were not upgraded.
From fdbdce701ab8145ae234c9d401109dff4e4106cb Mon Sep 17 00:00:00 2001
From: Aditya A <aditya.a@oracle.com>
Date: Thu, 17 May 2018 16:11:43 +0530
Subject: [PATCH] Bug #26390736 THE FIELD TABLE_NAME (VARCHAR(64)) FROM
MYSQL.INNODB_TABLE_STATS CAN OVERFLOW.
In mysql.innodb_index_stats and mysql.innodb_table_stats
tables the table name column didn't take into consideration
partition names which can be more than varchar(64).
2018-08-02 16:35:24 +02:00
-- Copyright (c) 2007, 2018, Oracle and/or its affiliates.
2019-09-23 16:35:29 +02:00
-- Copyright (c) 2008, 2019, MariaDB Corporation.
--
2010-01-12 02:47:27 +01:00
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
2019-05-11 20:29:06 +02:00
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
2010-01-12 02:47:27 +01:00
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 = ' ' ;
2012-11-15 13:11:35 +01:00
2020-01-13 20:07:04 +01:00
set @ orig_storage_engine = @ @ default_storage_engine ;
set default_storage_engine = Aria ;
2007-02-26 11:49:24 +01:00
2017-12-11 20:26:21 +01:00
set system_versioning_alter_history = keep ;
2017-06-15 15:02:32 +02:00
2014-06-05 09:04:43 +02:00
set @ have_innodb = ( select count ( engine ) from information_schema . engines where engine = ' INNODB ' and support ! = ' NO ' ) ;
2018-08-02 16:59:11 +02:00
SET @ innodb_or_aria = IF ( @ have_innodb < > 0 , ' InnoDB ' , ' Aria ' ) ;
2014-06-05 09:04:43 +02:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS db ( Host char ( 255 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 128 ) binary DEFAULT ' ' NOT NULL , Select_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Insert_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Update_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Delete_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Create_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Drop_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Grant_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , References_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Index_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Alter_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Create_tmp_table_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Lock_tables_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Create_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Show_view_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Create_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Alter_routine_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Execute_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Event_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Trigger_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , Delete_history_priv enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , PRIMARY KEY /* Host */ ( Host , Db , User ) , KEY User ( User ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_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
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS global_priv ( Host char ( 255 ) binary DEFAULT ' ' , User char ( 128 ) binary DEFAULT ' ' , Priv JSON NOT NULL DEFAULT ' {} ' CHECK ( JSON_VALID ( Priv ) ) , PRIMARY KEY ( Host , User ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Users and global privileges ' ;
2018-11-24 14:13:41 +01:00
2020-07-08 13:10:07 +02:00
set @ exists_user_view = EXISTS ( SELECT * FROM information_schema . VIEWS WHERE TABLE_CATALOG = ' def ' and TABLE_SCHEMA = ' mysql ' and TABLE_NAME = ' user ' ) ;
set @ exists_user_view_by_root = EXISTS ( SELECT * FROM information_schema . VIEWS WHERE TABLE_CATALOG = ' def ' and TABLE_SCHEMA = ' mysql ' and TABLE_NAME = ' user ' and DEFINER = ' mariadb.sys@localhost ' ) ;
2022-03-23 20:17:32 +01:00
set @ need_sys_user_creation = ( ( NOT @ exists_user_view ) OR @ exists_user_view_by_root ) ;
2020-07-08 13:10:07 +02:00
2020-02-19 17:50:30 +01:00
CREATE TEMPORARY TABLE tmp_user_sys LIKE global_priv ;
INSERT INTO tmp_user_sys ( Host , User , Priv ) VALUES ( ' localhost ' , ' mariadb.sys ' , ' {"access":0,"plugin":"mysql_native_password","authentication_string":"","account_locked":true,"password_last_changed":0} ' ) ;
2022-03-23 20:17:32 +01:00
INSERT IGNORE INTO global_priv SELECT * FROM tmp_user_sys WHERE 0 < > @ need_sys_user_creation ;
2020-02-19 17:50:30 +01:00
DROP TABLE tmp_user_sys ;
CREATE DEFINER = ' mariadb.sys ' @ ' localhost ' SQL SECURITY DEFINER VIEW IF NOT EXISTS user AS SELECT
2018-11-24 14:13:41 +01:00
Host ,
User ,
IF ( JSON_VALUE ( Priv , ' $.plugin ' ) IN ( ' mysql_native_password ' , ' mysql_old_password ' ) , IFNULL ( JSON_VALUE ( Priv , ' $.authentication_string ' ) , ' ' ) , ' ' ) AS Password ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 1 , ' Y ' , ' N ' ) AS Select_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 2 , ' Y ' , ' N ' ) AS Insert_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 4 , ' Y ' , ' N ' ) AS Update_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 8 , ' Y ' , ' N ' ) AS Delete_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 16 , ' Y ' , ' N ' ) AS Create_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 32 , ' Y ' , ' N ' ) AS Drop_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 64 , ' Y ' , ' N ' ) AS Reload_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 128 , ' Y ' , ' N ' ) AS Shutdown_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 256 , ' Y ' , ' N ' ) AS Process_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 512 , ' Y ' , ' N ' ) AS File_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 1024 , ' Y ' , ' N ' ) AS Grant_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 2048 , ' Y ' , ' N ' ) AS References_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 4096 , ' Y ' , ' N ' ) AS Index_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 8192 , ' Y ' , ' N ' ) AS Alter_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 16384 , ' Y ' , ' N ' ) AS Show_db_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 32768 , ' Y ' , ' N ' ) AS Super_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 65536 , ' Y ' , ' N ' ) AS Create_tmp_table_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 131072 , ' Y ' , ' N ' ) AS Lock_tables_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 262144 , ' Y ' , ' N ' ) AS Execute_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 524288 , ' Y ' , ' N ' ) AS Repl_slave_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 1048576 , ' Y ' , ' N ' ) AS Repl_client_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 2097152 , ' Y ' , ' N ' ) AS Create_view_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 4194304 , ' Y ' , ' N ' ) AS Show_view_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 8388608 , ' Y ' , ' N ' ) AS Create_routine_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 16777216 , ' Y ' , ' N ' ) AS Alter_routine_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 33554432 , ' Y ' , ' N ' ) AS Create_user_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 67108864 , ' Y ' , ' N ' ) AS Event_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 134217728 , ' Y ' , ' N ' ) AS Trigger_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 268435456 , ' Y ' , ' N ' ) AS Create_tablespace_priv ,
IF ( JSON_VALUE ( Priv , ' $.access ' ) & 536870912 , ' Y ' , ' N ' ) AS Delete_history_priv ,
ELT ( IFNULL ( JSON_VALUE ( Priv , ' $.ssl_type ' ) , 0 ) + 1 , ' ' , ' ANY ' , ' X509 ' , ' SPECIFIED ' ) AS ssl_type ,
IFNULL ( JSON_VALUE ( Priv , ' $.ssl_cipher ' ) , ' ' ) AS ssl_cipher ,
IFNULL ( JSON_VALUE ( Priv , ' $.x509_issuer ' ) , ' ' ) AS x509_issuer ,
IFNULL ( JSON_VALUE ( Priv , ' $.x509_subject ' ) , ' ' ) AS x509_subject ,
CAST ( IFNULL ( JSON_VALUE ( Priv , ' $.max_questions ' ) , 0 ) AS UNSIGNED ) AS max_questions ,
CAST ( IFNULL ( JSON_VALUE ( Priv , ' $.max_updates ' ) , 0 ) AS UNSIGNED ) AS max_updates ,
CAST ( IFNULL ( JSON_VALUE ( Priv , ' $.max_connections ' ) , 0 ) AS UNSIGNED ) AS max_connections ,
CAST ( IFNULL ( JSON_VALUE ( Priv , ' $.max_user_connections ' ) , 0 ) AS SIGNED ) AS max_user_connections ,
IFNULL ( JSON_VALUE ( Priv , ' $.plugin ' ) , ' ' ) AS plugin ,
IFNULL ( JSON_VALUE ( Priv , ' $.authentication_string ' ) , ' ' ) AS authentication_string ,
2021-02-02 13:57:16 +01:00
IF ( IFNULL ( JSON_VALUE ( Priv , ' $.password_last_changed ' ) , 1 ) = 0 , ' Y ' , ' N ' ) AS password_expired ,
2018-11-24 14:13:41 +01:00
ELT ( IFNULL ( JSON_VALUE ( Priv , ' $.is_role ' ) , 0 ) + 1 , ' N ' , ' Y ' ) AS is_role ,
IFNULL ( JSON_VALUE ( Priv , ' $.default_role ' ) , ' ' ) AS default_role ,
CAST ( IFNULL ( JSON_VALUE ( Priv , ' $.max_statement_time ' ) , 0 . 0 ) AS DECIMAL ( 12 , 6 ) ) AS max_statement_time
FROM global_priv ;
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 ;
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS roles_mapping ( Host char ( 255 ) binary DEFAULT ' ' NOT NULL , User char ( 128 ) binary DEFAULT ' ' NOT NULL , Role char ( 128 ) binary DEFAULT ' ' NOT NULL , Admin_option enum ( ' N ' , ' Y ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , UNIQUE ( Host , User , Role ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Granted roles ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02: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 utf8mb3_general_ci NOT NULL , PRIMARY KEY ( name ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' User defined functions ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS plugin ( name varchar ( 64 ) DEFAULT ' ' NOT NULL , dl varchar ( 128 ) DEFAULT ' ' NOT NULL , PRIMARY KEY ( name ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci comment = ' MySQL plugins ' ;
2007-02-27 11:39:29 +01:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS servers ( Server_name char ( 64 ) NOT NULL DEFAULT ' ' , Host varchar ( 2048 ) NOT NULL DEFAULT ' ' , Db char ( 64 ) NOT NULL DEFAULT ' ' , Username char ( 128 ) 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 varchar ( 512 ) NOT NULL DEFAULT ' ' , PRIMARY KEY ( Server_name ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 comment = ' MySQL Foreign Servers table ' ;
2007-02-27 11:39:29 +01:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS tables_priv ( Host char ( 255 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 128 ) binary DEFAULT ' ' NOT NULL , Table_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Grantor varchar ( 384 ) DEFAULT ' ' NOT NULL , Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , Table_priv set ( ' Select ' , ' Insert ' , ' Update ' , ' Delete ' , ' Create ' , ' Drop ' , ' Grant ' , ' References ' , ' Index ' , ' Alter ' , ' Create View ' , ' Show view ' , ' Trigger ' , ' Delete versioning rows ' ) COLLATE utf8mb3_general_ci DEFAULT ' ' NOT NULL , Column_priv set ( ' Select ' , ' Insert ' , ' Update ' , ' References ' ) COLLATE utf8mb3_general_ci DEFAULT ' ' NOT NULL , PRIMARY KEY ( Host , Db , User , Table_name ) , KEY Grantor ( Grantor ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Table privileges ' ;
2007-02-26 11:49:24 +01:00
2020-02-19 17:50:30 +01:00
CREATE TEMPORARY TABLE tmp_user_sys LIKE tables_priv ;
2020-07-23 18:57:40 +02:00
INSERT INTO tmp_user_sys ( Host , Db , User , Table_name , Grantor , Timestamp , Table_priv ) VALUES ( ' localhost ' , ' mysql ' , ' mariadb.sys ' , ' global_priv ' , ' root@localhost ' , ' 0 ' , ' Select,Delete ' ) ;
2022-03-23 20:17:32 +01:00
INSERT IGNORE INTO tables_priv SELECT * FROM tmp_user_sys WHERE 0 < > @ need_sys_user_creation ;
2020-02-19 17:50:30 +01:00
DROP TABLE tmp_user_sys ;
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS columns_priv ( Host char ( 255 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 128 ) binary DEFAULT ' ' NOT NULL , Table_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Column_name char ( 64 ) binary DEFAULT ' ' NOT NULL , Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , Column_priv set ( ' Select ' , ' Insert ' , ' Update ' , ' References ' ) COLLATE utf8mb3_general_ci DEFAULT ' ' NOT NULL , PRIMARY KEY ( Host , Db , User , Table_name , Column_name ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Column privileges ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 text not null , primary key ( help_topic_id ) , unique index ( name ) ) engine = Aria transactional = 0 CHARACTER SET utf8mb3 comment = ' help topics ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 text not null , primary key ( help_category_id ) , unique index ( name ) ) engine = Aria transactional = 0 CHARACTER SET utf8mb3 comment = ' help categories ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 = Aria transactional = 0 CHARACTER SET utf8mb3 comment = ' keyword-topic relation ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 = Aria transactional = 0 CHARACTER SET utf8mb3 comment = ' help keywords ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 = Aria transactional = 1 CHARACTER SET utf8mb3 comment = ' Time zone names ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment , Use_leap_seconds enum ( ' Y ' , ' N ' ) COLLATE utf8mb3_general_ci DEFAULT ' N ' NOT NULL , PRIMARY KEY /* TzId */ ( Time_zone_id ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 comment = ' Time zones ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 = Aria transactional = 1 CHARACTER SET utf8mb3 comment = ' Time zone transitions ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 = Aria transactional = 1 CHARACTER SET utf8mb3 comment = ' Time zone transition types ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
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 = Aria transactional = 1 CHARACTER SET utf8mb3 comment = ' Leap seconds information for time zones ' ;
2007-02-26 11:49:24 +01:00
2023-06-27 16:43:31 +02:00
CREATE TABLE IF NOT EXISTS proc ( db char ( 64 ) collate utf8mb3_bin DEFAULT ' ' NOT NULL , name char ( 64 ) DEFAULT ' ' NOT NULL , type enum ( ' FUNCTION ' , ' PROCEDURE ' , ' PACKAGE ' , ' PACKAGE BODY ' ) 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 longblob NOT NULL , body longblob NOT NULL , definer varchar ( 384 ) collate utf8mb3_bin DEFAULT ' ' NOT NULL , created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , modified timestamp NOT NULL DEFAULT ' 0000-00-00 00:00:00 ' , sql_mode set ( ' REAL_AS_FLOAT ' , ' PIPES_AS_CONCAT ' , ' ANSI_QUOTES ' , ' IGNORE_SPACE ' , ' IGNORE_BAD_TABLE_OPTIONS ' , ' 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 ' , ' NO_ENGINE_SUBSTITUTION ' , ' PAD_CHAR_TO_FULL_LENGTH ' , ' EMPTY_STRING_IS_NULL ' , ' SIMULTANEOUS_ASSIGNMENT ' , ' TIME_ROUND_FRACTIONAL ' ) DEFAULT ' ' NOT NULL , comment text collate utf8mb3_bin NOT NULL , character_set_client char ( 32 ) collate utf8mb3_bin , collation_connection char ( 64 ) collate utf8mb3_bin , db_collation char ( 64 ) collate utf8mb3_bin , body_utf8 longblob , aggregate enum ( ' NONE ' , ' GROUP ' ) DEFAULT ' NONE ' NOT NULL , PRIMARY KEY ( db , name , type ) ) engine = Aria transactional = 1 character set utf8mb3 comment = ' Stored Procedures ' ;
2007-02-26 11:49:24 +01:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS procs_priv ( Host char ( 255 ) binary DEFAULT ' ' NOT NULL , Db char ( 64 ) binary DEFAULT ' ' NOT NULL , User char ( 128 ) binary DEFAULT ' ' NOT NULL , Routine_name char ( 64 ) COLLATE utf8mb3_general_ci DEFAULT ' ' NOT NULL , Routine_type enum ( ' FUNCTION ' , ' PROCEDURE ' , ' PACKAGE ' , ' PACKAGE BODY ' ) NOT NULL , Grantor varchar ( 384 ) DEFAULT ' ' NOT NULL , Proc_priv set ( ' Execute ' , ' Alter Routine ' , ' Grant ' ) COLLATE utf8mb3_general_ci DEFAULT ' ' NOT NULL , Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , PRIMARY KEY ( Host , Db , User , Routine_name , Routine_type ) , KEY Grantor ( Grantor ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Procedure privileges ' ;
2007-02-26 11:49:24 +01:00
2007-02-27 11:39:29 +01:00
2013-06-16 20:26:40 +02:00
-- Create general_log if CSV is enabled.
2013-08-13 13:35:36 +02:00
SET @ have_csv = ( SELECT support FROM information_schema . engines WHERE engine = ' CSV ' ) ;
2022-10-21 12:13:17 +02:00
SET @ str = IF ( @ have_csv = ' YES ' , ' CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_host MEDIUMTEXT NOT NULL, thread_id BIGINT(21) UNSIGNED NOT NULL, server_id INTEGER UNSIGNED NOT NULL, command_type VARCHAR(64) NOT NULL, argument MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8mb3 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.
2023-10-06 13:34:01 +02:00
SET @ str = IF ( @ have_csv = ' YES ' , ' CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_host MEDIUMTEXT NOT NULL, query_time TIME(6) NOT NULL, lock_time TIME(6) NOT NULL, rows_sent BIGINT UNSIGNED NOT NULL, rows_examined BIGINT UNSIGNED NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL, thread_id BIGINT(21) UNSIGNED NOT NULL, rows_affected BIGINT UNSIGNED NOT NULL) engine=CSV CHARACTER SET utf8mb3 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
2023-06-27 16:43:31 +02:00
CREATE TABLE IF NOT EXISTS event ( db char ( 64 ) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL default ' ' , name char ( 64 ) CHARACTER SET utf8mb3 NOT NULL default ' ' , body longblob NOT NULL , definer varchar ( 384 ) CHARACTER SET utf8mb3 COLLATE utf8mb3_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 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , modified TIMESTAMP NOT NULL DEFAULT ' 0000-00-00 00:00:00 ' , 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 ' , ' IGNORE_BAD_TABLE_OPTIONS ' , ' 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 ' , ' NO_ENGINE_SUBSTITUTION ' , ' PAD_CHAR_TO_FULL_LENGTH ' , ' EMPTY_STRING_IS_NULL ' , ' SIMULTANEOUS_ASSIGNMENT ' , ' TIME_ROUND_FRACTIONAL ' ) DEFAULT ' ' NOT NULL , comment char ( 64 ) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL default ' ' , originator INTEGER UNSIGNED NOT NULL , time_zone char ( 64 ) CHARACTER SET latin1 NOT NULL DEFAULT ' SYSTEM ' , character_set_client char ( 32 ) collate utf8mb3_bin , collation_connection char ( 64 ) collate utf8mb3_bin , db_collation char ( 64 ) collate utf8mb3_bin , body_utf8 longblob , PRIMARY KEY ( db , name ) ) engine = Aria transactional = 1 DEFAULT CHARSET = utf8mb3 COMMENT ' Events ' ;
2012-08-22 23:32:25 +02:00
2013-09-13 10:44:51 +02:00
SET @ create_innodb_table_stats = " CREATE TABLE IF NOT EXISTS innodb_table_stats (
2012-08-22 23:32:25 +02:00
database_name VARCHAR ( 64 ) NOT NULL ,
MDEV-14637: Fix hang due to persistent statistics
Similar to the tables SYS_FOREIGN and SYS_FOREIGN_COLS,
the tables mysql.innodb_table_stats and mysql.innodb_index_stats
are updated by the InnoDB internal SQL parser, which fails to
enforce the size limits of the data. Due to this, it is possible
for InnoDB to hang when there are persistent statistics defined on
partitioned tables where the total length of table name,
partition name and subpartition name exceeds the incorrectly
defined limit VARCHAR(64). That column should have been defined
as VARCHAR(199).
btr_node_ptr_max_size(): Interpret the VARCHAR(64) as VARCHAR(199),
to prevent a hang in the case that the upgrade script has not been
run.
dict_table_schema_check(): Ignore difference in the length of the
table_name column.
ha_innobase::max_supported_key_length(): For innodb_page_size=4k,
return a larger value so that the table mysql.innodb_index_stats
can be created. This could allow "impossible" tables to be created,
such that it is not possible to insert anything into a secondary
index when both the secondary key and the primary key are long,
but this is the easiest and most consistent way. The Oracle fix
would only ignore the maximum length violation for the two
statistics tables.
os_file_get_status_posix(), os_file_get_status_win32(): Handle
ENAMETOOLONG as well.
This patch is based on the following change in MySQL 5.7.23.
Not all changes were applied, and our variant allows persistent
statistics to work without hangs even if the table definitions
were not upgraded.
From fdbdce701ab8145ae234c9d401109dff4e4106cb Mon Sep 17 00:00:00 2001
From: Aditya A <aditya.a@oracle.com>
Date: Thu, 17 May 2018 16:11:43 +0530
Subject: [PATCH] Bug #26390736 THE FIELD TABLE_NAME (VARCHAR(64)) FROM
MYSQL.INNODB_TABLE_STATS CAN OVERFLOW.
In mysql.innodb_index_stats and mysql.innodb_table_stats
tables the table name column didn't take into consideration
partition names which can be more than varchar(64).
2018-08-02 16:35:24 +02:00
table_name VARCHAR ( 199 ) NOT NULL ,
2013-06-16 20:26:40 +02:00
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
2012-08-22 23:32:25 +02:00
n_rows BIGINT UNSIGNED NOT NULL ,
clustered_index_size BIGINT UNSIGNED NOT NULL ,
sum_of_other_index_sizes BIGINT UNSIGNED NOT NULL ,
PRIMARY KEY ( database_name , table_name )
2022-10-21 12:13:17 +02:00
) ENGINE = INNODB DEFAULT CHARSET = utf8mb3 COLLATE = utf8mb3_bin STATS_PERSISTENT = 0 " ;
2012-08-22 23:32:25 +02:00
2013-09-13 10:44:51 +02:00
SET @ create_innodb_index_stats = " CREATE TABLE IF NOT EXISTS innodb_index_stats (
2012-08-22 23:32:25 +02:00
database_name VARCHAR ( 64 ) NOT NULL ,
MDEV-14637: Fix hang due to persistent statistics
Similar to the tables SYS_FOREIGN and SYS_FOREIGN_COLS,
the tables mysql.innodb_table_stats and mysql.innodb_index_stats
are updated by the InnoDB internal SQL parser, which fails to
enforce the size limits of the data. Due to this, it is possible
for InnoDB to hang when there are persistent statistics defined on
partitioned tables where the total length of table name,
partition name and subpartition name exceeds the incorrectly
defined limit VARCHAR(64). That column should have been defined
as VARCHAR(199).
btr_node_ptr_max_size(): Interpret the VARCHAR(64) as VARCHAR(199),
to prevent a hang in the case that the upgrade script has not been
run.
dict_table_schema_check(): Ignore difference in the length of the
table_name column.
ha_innobase::max_supported_key_length(): For innodb_page_size=4k,
return a larger value so that the table mysql.innodb_index_stats
can be created. This could allow "impossible" tables to be created,
such that it is not possible to insert anything into a secondary
index when both the secondary key and the primary key are long,
but this is the easiest and most consistent way. The Oracle fix
would only ignore the maximum length violation for the two
statistics tables.
os_file_get_status_posix(), os_file_get_status_win32(): Handle
ENAMETOOLONG as well.
This patch is based on the following change in MySQL 5.7.23.
Not all changes were applied, and our variant allows persistent
statistics to work without hangs even if the table definitions
were not upgraded.
From fdbdce701ab8145ae234c9d401109dff4e4106cb Mon Sep 17 00:00:00 2001
From: Aditya A <aditya.a@oracle.com>
Date: Thu, 17 May 2018 16:11:43 +0530
Subject: [PATCH] Bug #26390736 THE FIELD TABLE_NAME (VARCHAR(64)) FROM
MYSQL.INNODB_TABLE_STATS CAN OVERFLOW.
In mysql.innodb_index_stats and mysql.innodb_table_stats
tables the table name column didn't take into consideration
partition names which can be more than varchar(64).
2018-08-02 16:35:24 +02:00
table_name VARCHAR ( 199 ) NOT NULL ,
2012-08-22 23:32:25 +02:00
index_name VARCHAR ( 64 ) NOT NULL ,
2013-06-16 20:26:40 +02:00
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
2012-08-22 23:32:25 +02:00
/* there are at least:
stat_name = ' size '
stat_name = ' n_leaf_pages '
stat_name = ' n_diff_pfx% ' * /
stat_name VARCHAR ( 64 ) NOT NULL ,
stat_value BIGINT UNSIGNED NOT NULL ,
sample_size BIGINT UNSIGNED ,
stat_description VARCHAR ( 1024 ) NOT NULL ,
2013-06-16 20:26:40 +02:00
PRIMARY KEY ( database_name , table_name , index_name , stat_name )
2022-10-21 12:13:17 +02:00
) ENGINE = INNODB DEFAULT CHARSET = utf8mb3 COLLATE = utf8mb3_bin STATS_PERSISTENT = 0 " ;
2013-09-13 10:44:51 +02:00
2017-11-10 15:54:46 +01:00
SET @ create_transaction_registry = " CREATE TABLE IF NOT EXISTS transaction_registry (
transaction_id BIGINT UNSIGNED NOT NULL ,
commit_id BIGINT UNSIGNED NOT NULL ,
begin_timestamp TIMESTAMP ( 6 ) NOT NULL DEFAULT ' 0000-00-00 00:00:00.000000 ' ,
commit_timestamp TIMESTAMP ( 6 ) NOT NULL DEFAULT ' 0000-00-00 00:00:00.000000 ' ,
isolation_level ENUM ( ' READ-UNCOMMITTED ' , ' READ-COMMITTED ' ,
' REPEATABLE-READ ' , ' SERIALIZABLE ' ) NOT NULL ,
PRIMARY KEY ( transaction_id ) ,
UNIQUE KEY ( commit_id ) ,
INDEX ( begin_timestamp ) ,
INDEX ( commit_timestamp , transaction_id )
2022-10-21 12:13:17 +02:00
) ENGINE = INNODB DEFAULT CHARSET = utf8mb3 COLLATE = utf8mb3_bin STATS_PERSISTENT = 0 " ;
2017-11-10 15:54:46 +01:00
2013-09-13 10:44:51 +02:00
SET @ str = IF ( @ have_innodb < > 0 , @ create_innodb_table_stats , " SET @dummy = 0 " ) ;
PREPARE stmt FROM @ str ;
EXECUTE stmt ;
DROP PREPARE stmt ;
2012-08-22 23:32:25 +02:00
2013-09-13 10:44:51 +02:00
SET @ str = IF ( @ have_innodb < > 0 , @ create_innodb_index_stats , " SET @dummy = 0 " ) ;
PREPARE stmt FROM @ str ;
EXECUTE stmt ;
DROP PREPARE stmt ;
2013-06-16 20:26:40 +02:00
2017-11-10 15:54:46 +01:00
SET @ str = IF ( @ have_innodb < > 0 , @ create_transaction_registry , " SET @dummy = 0 " ) ;
PREPARE stmt FROM @ str ;
EXECUTE stmt ;
DROP PREPARE stmt ;
2013-06-16 20:26:40 +02:00
SET @ cmd = " CREATE TABLE IF NOT EXISTS slave_relay_log_info (
Number_of_lines INTEGER UNSIGNED NOT NULL COMMENT ' Number of lines in the file or rows in the table. Used to version table definitions. ' ,
2022-10-21 12:13:17 +02:00
Relay_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL COMMENT ' The name of the current relay log file. ' ,
2013-06-16 20:26:40 +02:00
Relay_log_pos BIGINT UNSIGNED NOT NULL COMMENT ' The relay log position of the last executed event. ' ,
2022-10-21 12:13:17 +02:00
Master_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL COMMENT ' The name of the master binary log file from which the events in the relay log file were read. ' ,
2013-06-16 20:26:40 +02:00
Master_log_pos BIGINT UNSIGNED NOT NULL COMMENT ' The master log position of the last executed event. ' ,
Sql_delay INTEGER NOT NULL COMMENT ' The number of seconds that the slave must lag behind the master. ' ,
Number_of_workers INTEGER UNSIGNED NOT NULL ,
Id INTEGER UNSIGNED NOT NULL COMMENT ' Internal Id that uniquely identifies this record. ' ,
2022-10-21 12:13:17 +02:00
PRIMARY KEY ( Id ) ) DEFAULT CHARSET = utf8mb3 STATS_PERSISTENT = 0 COMMENT ' Relay Log Information ' " ;
2013-06-16 20:26:40 +02:00
2018-08-02 16:59:11 +02:00
SET @ str = CONCAT ( @ cmd , ' ENGINE= ' , @ innodb_or_aria ) ;
2013-06-16 20:26:40 +02:00
-- Don't create the table; MariaDB will have another implementation
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
SET @ cmd = " CREATE TABLE IF NOT EXISTS slave_master_info (
Number_of_lines INTEGER UNSIGNED NOT NULL COMMENT ' Number of lines in the file. ' ,
2022-10-21 12:13:17 +02:00
Master_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL COMMENT ' The name of the master binary log currently being read from the master. ' ,
2013-06-16 20:26:40 +02:00
Master_log_pos BIGINT UNSIGNED NOT NULL COMMENT ' The master log position of the last read event. ' ,
2022-10-21 12:13:17 +02:00
Host CHAR ( 255 ) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The host name of the master. ' ,
User_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The user name used to connect to the master. ' ,
User_password TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The password used to connect to the master. ' ,
2013-06-16 20:26:40 +02:00
Port INTEGER UNSIGNED NOT NULL COMMENT ' The network port used to connect to the master. ' ,
Connect_retry INTEGER UNSIGNED NOT NULL COMMENT ' The period (in seconds) that the slave will wait before trying to reconnect to the master. ' ,
Enabled_ssl BOOLEAN NOT NULL COMMENT ' Indicates whether the server supports SSL connections. ' ,
2022-10-21 12:13:17 +02:00
Ssl_ca TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The file used for the Certificate Authority (CA) certificate. ' ,
Ssl_capath TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The path to the Certificate Authority (CA) certificates. ' ,
Ssl_cert TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The name of the SSL certificate file. ' ,
Ssl_cipher TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The name of the cipher in use for the SSL connection. ' ,
Ssl_key TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The name of the SSL key file. ' ,
2013-06-16 20:26:40 +02:00
Ssl_verify_server_cert BOOLEAN NOT NULL COMMENT ' Whether to verify the server certificate. ' ,
Heartbeat FLOAT NOT NULL COMMENT ' ' ,
2022-10-21 12:13:17 +02:00
Bind TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' Displays which interface is employed when connecting to the MySQL server ' ,
Ignored_server_ids TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The number of server IDs to be ignored, followed by the actual server IDs ' ,
Uuid TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The master server uuid. ' ,
2013-06-16 20:26:40 +02:00
Retry_count BIGINT UNSIGNED NOT NULL COMMENT ' Number of reconnect attempts, to the master, before giving up. ' ,
2022-10-21 12:13:17 +02:00
Ssl_crl TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The file used for the Certificate Revocation List (CRL) ' ,
Ssl_crlpath TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin COMMENT ' The path used for Certificate Revocation List (CRL) files ' ,
2013-06-16 20:26:40 +02:00
Enabled_auto_position BOOLEAN NOT NULL COMMENT ' Indicates whether GTIDs will be used to retrieve events from the master. ' ,
2022-10-21 12:13:17 +02:00
PRIMARY KEY ( Host , Port ) ) DEFAULT CHARSET = utf8mb3 STATS_PERSISTENT = 0 COMMENT ' Master Information ' " ;
2013-06-16 20:26:40 +02:00
2018-08-02 16:59:11 +02:00
SET @ str = CONCAT ( @ cmd , ' ENGINE= ' , @ innodb_or_aria ) ;
2013-06-16 20:26:40 +02:00
-- Don't create the table; MariaDB will have another implementation
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
SET @ cmd = " CREATE TABLE IF NOT EXISTS slave_worker_info (
Id INTEGER UNSIGNED NOT NULL ,
2022-10-21 12:13:17 +02:00
Relay_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL ,
2013-06-16 20:26:40 +02:00
Relay_log_pos BIGINT UNSIGNED NOT NULL ,
2022-10-21 12:13:17 +02:00
Master_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL ,
2013-06-16 20:26:40 +02:00
Master_log_pos BIGINT UNSIGNED NOT NULL ,
2022-10-21 12:13:17 +02:00
Checkpoint_relay_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL ,
2013-06-16 20:26:40 +02:00
Checkpoint_relay_log_pos BIGINT UNSIGNED NOT NULL ,
2022-10-21 12:13:17 +02:00
Checkpoint_master_log_name TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL ,
2013-06-16 20:26:40 +02:00
Checkpoint_master_log_pos BIGINT UNSIGNED NOT NULL ,
Checkpoint_seqno INT UNSIGNED NOT NULL ,
Checkpoint_group_size INTEGER UNSIGNED NOT NULL ,
Checkpoint_group_bitmap BLOB NOT NULL ,
2022-10-21 12:13:17 +02:00
PRIMARY KEY ( Id ) ) DEFAULT CHARSET = utf8mb3 STATS_PERSISTENT = 0 COMMENT ' Worker Information ' " ;
2013-06-16 20:26:40 +02:00
2018-08-02 16:59:11 +02:00
SET @ str = CONCAT ( @ cmd , ' ENGINE= ' , @ innodb_or_aria ) ;
2013-06-16 20:26:40 +02:00
-- Don't create the table; MariaDB will have another implementation
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS proxies_priv ( Host char ( 255 ) binary DEFAULT ' ' NOT NULL , User char ( 128 ) binary DEFAULT ' ' NOT NULL , Proxied_host char ( 255 ) binary DEFAULT ' ' NOT NULL , Proxied_user char ( 128 ) binary DEFAULT ' ' NOT NULL , With_grant BOOL DEFAULT 0 NOT NULL , Grantor varchar ( 384 ) DEFAULT ' ' NOT NULL , Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , PRIMARY KEY /* Host */ ( Host , User , Proxied_host , Proxied_user ) , KEY Grantor ( Grantor ) ) engine = Aria transactional = 1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' User proxy privileges ' ;
2010-08-09 10:32:50 +02:00
2010-11-02 16:45:26 +01:00
-- Remember for later if proxies_priv table already existed
set @ had_proxies_priv_table = @ @ warning_count ! = 0 ;
2012-03-19 09:35:32 +01:00
2018-11-24 14:13:41 +01:00
-- The following needs to be done both for new installations
-- and for upgrades
CREATE TEMPORARY TABLE tmp_proxies_priv LIKE proxies_priv ;
INSERT INTO tmp_proxies_priv VALUES ( ' localhost ' , ' root ' , ' ' , ' ' , TRUE , ' ' , now ( ) ) ;
MDEV-21194: mariadb-install-db doesn't properly grant proxy privileges to all created user accounts
mariadb-install-db --auth-root-authentication-method=normal created 4
root accounts by default, but only two of these had PROXY privilege
granted.
mariadb-install-db (default option
--auth-root-authentication-method=socket) as non-root user also didn't
grant PROXY priv to the created nonroot@localhost user.
To fix this, in mysql_system_tables_data.sql, we re-use tmp_user_nopasswd
as this contains the list of all root users.
REPLACE INTO tmp_proxies_priv SELECT @current_hostname, IFNULL(@auth_root_socket, 'root')
creates the $user@$current_host but will not error if @auth_root_socket
is null. Note @current_hostname lines are filtered out with
--cross-bootstrap in mariadb-install-db so it was needed to include this
expression for consistency.
Like the existing mysql_system_tables.sql is used to create teh
$user@localhost proxies_priv.
Test cases roles.acl_statistics, perfschema,privilege_table_io depends on the number of proxy users.
After:
--auth-root-authentication-method=normal:
MariaDB [mysql]> select * from global_priv;
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------+
| Host | User | Priv |
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------+
| localhost | mariadb.sys | {"access":0,"plugin":"mysql_native_password","authentication_string":"","account_locked":true,"password_last_changed":0} |
| localhost | root | {"access":18446744073709551615} |
| bark | root | {"access":18446744073709551615} |
| 127.0.0.1 | root | {"access":18446744073709551615} |
| ::1 | root | {"access":18446744073709551615} |
| localhost | | {} |
| bark | | {} |
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------+
7 rows in set (0.001 sec)
MariaDB [mysql]> select * from proxies_priv;
+-----------+------+--------------+--------------+------------+---------+---------------------+
| Host | User | Proxied_host | Proxied_user | With_grant | Grantor | Timestamp |
+-----------+------+--------------+--------------+------------+---------+---------------------+
| localhost | root | | | 1 | | 2023-07-10 12:12:24 |
| 127.0.0.1 | root | | | 1 | | 2023-07-10 12:12:24 |
| ::1 | root | | | 1 | | 2023-07-10 12:12:24 |
| bark | root | | | 1 | | 2023-07-10 12:12:24 |
+-----------+------+--------------+--------------+------------+---------+---------------------+
--auth-root-authentication-method=socket:
MariaDB [mysql]> select * from proxies_priv;
+-----------+------+--------------+--------------+------------+---------+---------------------+
| Host | User | Proxied_host | Proxied_user | With_grant | Grantor | Timestamp |
+-----------+------+--------------+--------------+------------+---------+---------------------+
| localhost | root | | | 1 | | 2023-07-10 12:11:55 |
| localhost | dan | | | 1 | | 2023-07-10 12:11:55 |
| bark | dan | | | 1 | | 2023-07-10 12:11:55 |
+-----------+------+--------------+--------------+------------+---------+---------------------+
3 rows in set (0.017 sec)
MariaDB [mysql]> select * from global_priv;
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Host | User | Priv |
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| localhost | mariadb.sys | {"access":0,"plugin":"mysql_native_password","authentication_string":"","account_locked":true,"password_last_changed":0} |
| localhost | root | {"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]} |
| localhost | dan | {"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]} |
| localhost | | {} |
| bark | | {} |
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------+
5 rows in set (0.000 sec)
MariaDB [mysql]> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for dan@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `dan`@`localhost` IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'dan'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2023-07-10 04:15:30 +02:00
REPLACE INTO tmp_proxies_priv SELECT ' localhost ' , IFNULL ( @ auth_root_socket , ' root ' ) , ' ' , ' ' , TRUE , ' ' , now ( ) FROM DUAL ;
2018-11-24 14:13:41 +01:00
INSERT INTO proxies_priv SELECT * FROM tmp_proxies_priv WHERE @ had_proxies_priv_table = 0 ;
DROP TABLE tmp_proxies_priv ;
2013-06-16 20:26:40 +02:00
--
-- Tables unique for MariaDB
--
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS table_stats ( db_name varchar ( 64 ) NOT NULL , table_name varchar ( 64 ) NOT NULL , cardinality bigint ( 21 ) unsigned DEFAULT NULL , PRIMARY KEY ( db_name , table_name ) ) engine = Aria transactional = 0 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Statistics on Tables ' ;
2012-01-05 02:51:53 +01:00
2023-06-27 12:48:46 +02:00
CREATE TABLE IF NOT EXISTS column_stats ( db_name varchar ( 64 ) NOT NULL , table_name varchar ( 64 ) NOT NULL , column_name varchar ( 64 ) NOT NULL , min_value varbinary ( 255 ) DEFAULT NULL , max_value varbinary ( 255 ) DEFAULT NULL , null s_ratio decimal ( 12 , 4 ) DEFAULT NULL , avg_length decimal ( 12 , 4 ) DEFAULT NULL , avg_frequency decimal ( 12 , 4 ) DEFAULT NULL , hist_size tinyint unsigned , hist_type enum ( ' SINGLE_PREC_HB ' , ' DOUBLE_PREC_HB ' , ' JSON_HB ' ) , histogram longblob , PRIMARY KEY ( db_name , table_name , column_name ) ) engine = Aria transactional = 0 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Statistics on Columns ' ;
2012-01-05 02:51:53 +01:00
2022-10-21 12:13:17 +02:00
CREATE TABLE IF NOT EXISTS index_stats ( db_name varchar ( 64 ) NOT NULL , table_name varchar ( 64 ) NOT NULL , index_name varchar ( 64 ) NOT NULL , prefix_arity int ( 11 ) unsigned NOT NULL , avg_frequency decimal ( 12 , 4 ) DEFAULT NULL , PRIMARY KEY ( db_name , table_name , index_name , prefix_arity ) ) engine = Aria transactional = 0 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment = ' Statistics on Indexes ' ;
2013-11-13 15:40:46 +01:00
2017-03-24 12:07:07 +01:00
-- Note: This definition must be kept in sync with the one used in
-- build_gtid_pos_create_query() in sql/slave.cc
2014-06-05 09:04:43 +02:00
SET @ cmd = " CREATE TABLE IF NOT EXISTS gtid_slave_pos (
domain_id INT UNSIGNED NOT NULL ,
sub_id BIGINT UNSIGNED NOT NULL ,
server_id INT UNSIGNED NOT NULL ,
seq_no BIGINT UNSIGNED NOT NULL ,
2016-04-23 18:49:19 +02:00
PRIMARY KEY ( domain_id , sub_id ) ) CHARSET = latin1
2014-06-05 09:04:43 +02:00
COMMENT = ' Replication slave GTID position ' " ;
2018-08-02 16:59:11 +02:00
SET @ str = CONCAT ( @ cmd , ' ENGINE= ' , @ innodb_or_aria ) ;
2014-06-05 09:04:43 +02:00
PREPARE stmt FROM @ str ;
EXECUTE stmt ;
DROP PREPARE stmt ;
2020-01-13 20:07:04 +01:00
set default_storage_engine = @ orig_storage_engine ;
2016-05-01 18:10:51 +02:00
--
-- Drop some tables not used anymore in MariaDB
2018-08-02 16:59:11 +02:00
--
2016-05-01 18:10:51 +02:00
drop table if exists mysql . ndb_binlog_index ;
2018-08-16 19:12:13 +02:00
drop table if exists mysql . host ;