create database mysql;

use mysql;

set table_type=myisam;

CREATE TABLE 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,
	PRIMARY KEY Host (Host,Db,User), KEY User (User)
) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';

INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');
INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');

CREATE TABLE 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,
	PRIMARY KEY Host (Host,Db)
) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges;  Merged with database privileges';

CREATE TABLE 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,
	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';

INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);

CREATE TABLE 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';

CREATE TABLE 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') 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';

CREATE TABLE 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 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 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 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 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 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 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 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 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 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';

CREATE TABLE 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 DEFAULT '' NOT NULL,
	returns           char(64) DEFAULT '' NOT NULL,
	body              longblob DEFAULT '' 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,
	PRIMARY KEY (db,name,type)
) engine=MyISAM character set utf8 comment='Stored Procedures';

CREATE TABLE 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';
