2003-08-27 22:30:50 +03:00
|
|
|
-- This script converts any old privilege tables to privilege tables suitable
|
|
|
|
-- for MySQL 4.0.
|
|
|
|
|
|
|
|
-- You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
|
|
|
|
-- as this just means that your tables where already up to date.
|
|
|
|
-- This script is safe to run even if your tables are already up to date!
|
|
|
|
|
|
|
|
-- On unix, you should use the mysql_fix_privilege_tables script to execute
|
|
|
|
-- this sql script.
|
2004-03-19 18:33:38 +02:00
|
|
|
-- On windows you should do 'mysql --force mysql < mysql_fix_privilege_tables.sql'
|
2003-08-27 22:30:50 +03:00
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
ALTER TABLE user type=MyISAM;
|
|
|
|
ALTER TABLE db type=MyISAM;
|
|
|
|
ALTER TABLE host type=MyISAM;
|
|
|
|
ALTER TABLE func type=MyISAM;
|
|
|
|
ALTER TABLE columns_priv type=MyISAM;
|
|
|
|
ALTER TABLE tables_priv type=MyISAM;
|
2004-03-19 18:33:38 +02:00
|
|
|
ALTER TABLE user change Password Password char(41) binary not null;
|
2003-06-04 18:28:51 +03:00
|
|
|
ALTER TABLE user add File_priv enum('N','Y') NOT NULL;
|
|
|
|
CREATE TABLE IF NOT EXISTS func (
|
2004-03-19 18:33:38 +02:00
|
|
|
name char(64) binary DEFAULT '' NOT NULL,
|
2003-06-04 18:28:51 +03:00
|
|
|
ret tinyint(1) DEFAULT '0' NOT NULL,
|
|
|
|
dl char(128) DEFAULT '' NOT NULL,
|
|
|
|
type enum ('function','aggregate') NOT NULL,
|
|
|
|
PRIMARY KEY (name)
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Detect whether or not we had the Grant_priv column
|
|
|
|
SET @hadGrantPriv:=0;
|
|
|
|
SELECT @hadGrantPriv:=1 FROM user WHERE Grant_priv LIKE '%';
|
|
|
|
|
|
|
|
ALTER TABLE user add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
|
|
|
|
ALTER TABLE host add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
|
|
|
|
ALTER TABLE db add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
|
|
|
|
|
|
|
|
--- Fix privileges for old tables
|
|
|
|
UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE @hadGrantPriv = 0;
|
|
|
|
UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE @hadGrantPriv = 0;
|
|
|
|
UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE @hadGrantPriv = 0;
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
--
|
|
|
|
-- The second alter changes ssl_type to new 4.0.2 format
|
|
|
|
-- Adding columns needed by GRANT .. REQUIRE (openssl)"
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
ALTER TABLE user
|
|
|
|
ADD ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL,
|
|
|
|
ADD ssl_cipher BLOB NOT NULL,
|
|
|
|
ADD x509_issuer BLOB NOT NULL,
|
|
|
|
ADD x509_subject BLOB NOT NULL;
|
|
|
|
ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL;
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
--
|
|
|
|
-- Create tables_priv and columns_priv if they don't exists
|
|
|
|
--
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
CREATE TABLE IF NOT EXISTS tables_priv (
|
2004-03-19 18:33:38 +02:00
|
|
|
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,
|
2003-06-04 18:28:51 +03:00
|
|
|
Grantor char(77) DEFAULT '' NOT NULL,
|
|
|
|
Timestamp timestamp(14),
|
|
|
|
Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,
|
|
|
|
Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
|
|
|
|
PRIMARY KEY (Host,Db,User,Table_name)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS columns_priv (
|
|
|
|
Host char(60) DEFAULT '' NOT NULL,
|
|
|
|
Db char(60) DEFAULT '' NOT NULL,
|
|
|
|
User char(16) DEFAULT '' NOT NULL,
|
|
|
|
Table_name char(60) DEFAULT '' NOT NULL,
|
|
|
|
Column_name char(59) DEFAULT '' NOT NULL,
|
|
|
|
Timestamp timestamp(14),
|
|
|
|
Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
|
|
|
|
PRIMARY KEY (Host,Db,User,Table_name,Column_name)
|
|
|
|
);
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Name change of Type -> Column_priv from MySQL 3.22.12
|
|
|
|
--
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
ALTER TABLE columns_priv change Type Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL;
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
--
|
|
|
|
-- Add the new 'type' column to the func table.
|
|
|
|
--
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
ALTER TABLE func add type enum ('function','aggregate') NOT NULL;
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
--
|
|
|
|
-- Change the user,db and host tables to MySQL 4.0 format
|
|
|
|
--
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
# Detect whether we had Show_db_priv
|
|
|
|
SET @hadShowDbPriv:=0;
|
|
|
|
SELECT @hadShowDbPriv:=1 FROM user WHERE Show_db_priv LIKE '%';
|
|
|
|
|
|
|
|
ALTER TABLE user
|
2004-03-19 18:33:38 +02:00
|
|
|
ADD Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Alter_priv,
|
2003-06-04 18:28:51 +03:00
|
|
|
ADD Super_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Show_db_priv,
|
|
|
|
ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Super_priv,
|
|
|
|
ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Create_tmp_table_priv,
|
|
|
|
ADD Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Lock_tables_priv,
|
|
|
|
ADD Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Execute_priv,
|
|
|
|
ADD Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Repl_slave_priv;
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
-- Convert privileges so that users have similar privileges as before
|
|
|
|
|
|
|
|
UPDATE user SET Show_db_priv= Select_priv, Super_priv=Process_priv, Execute_priv=Process_priv, Create_tmp_table_priv='Y', Lock_tables_priv='Y', Repl_slave_priv=file_priv, Repl_client_priv=File_priv where user<>"" AND @hadShowDbPriv = 0;
|
|
|
|
|
|
|
|
|
|
|
|
-- Add fields that can be used to limit number of questions and connections
|
|
|
|
-- for some users.
|
2003-06-04 18:28:51 +03:00
|
|
|
|
|
|
|
ALTER TABLE user
|
|
|
|
ADD max_questions int(11) NOT NULL AFTER x509_subject,
|
|
|
|
ADD max_updates int(11) unsigned NOT NULL AFTER max_questions,
|
|
|
|
ADD max_connections int(11) unsigned NOT NULL AFTER max_updates;
|
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Add Create_tmp_table_priv and Lock_tables_priv to db and host
|
|
|
|
--
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
ALTER TABLE db
|
|
|
|
ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,
|
|
|
|
ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
|
|
|
|
ALTER TABLE host
|
|
|
|
ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,
|
|
|
|
ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
|
2003-10-06 22:56:34 +03:00
|
|
|
|
2004-03-19 18:33:38 +02:00
|
|
|
alter table db change Db Db char(64) binary DEFAULT '' NOT NULL;
|
|
|
|
alter table host change Db Db char(64) binary DEFAULT '' NOT NULL;
|
|
|
|
alter table user change max_questions max_questions int(11) unsigned DEFAULT 0 NOT NULL;
|
|
|
|
alter table tables_priv change Db Db char(64) binary DEFAULT '' NOT NULL, change Host Host char(60) binary DEFAULT '' NOT NULL, change User User char(16) binary DEFAULT '' NOT NULL, change Table_name Table_name char(64) binary DEFAULT '' NOT NULL;
|
|
|
|
alter table tables_priv add KEY Grantor (Grantor);
|
|
|
|
alter table columns_priv change Db Db char(64) binary DEFAULT '' NOT NULL, change Host Host char(60) binary DEFAULT '' NOT NULL, change User User char(16) binary DEFAULT '' NOT NULL, change Table_name Table_name char(64) binary DEFAULT '' NOT NULL, change Column_name Column_name char(64) binary DEFAULT '' NOT NULL;
|
|
|
|
|
|
|
|
alter table db comment='Database privileges';
|
|
|
|
alter table host comment='Host privileges; Merged with database privileges';
|
|
|
|
alter table user comment='Users and global privileges';
|
|
|
|
alter table func comment='User defined functions';
|
|
|
|
alter table tables_priv comment='Table privileges';
|
|
|
|
alter table columns_priv comment='Column privileges';
|
|
|
|
|
2003-10-06 22:56:34 +03:00
|
|
|
#
|
|
|
|
# Create some possible missing tables
|
|
|
|
#
|
|
|
|
CREATE TABLE IF NOT EXISTS help_topic (
|
|
|
|
help_topic_id int unsigned not null,
|
|
|
|
name varchar(64) not null,
|
|
|
|
help_category_id smallint unsigned not null,
|
|
|
|
description text not null,
|
|
|
|
example text not null,
|
|
|
|
url varchar(128) not null,
|
|
|
|
primary key (help_topic_id), unique index (name)
|
|
|
|
) comment='help topics';
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS help_category (
|
|
|
|
help_category_id smallint unsigned not null,
|
|
|
|
name varchar(64) not null,
|
|
|
|
parent_category_id smallint unsigned null,
|
|
|
|
url varchar(128) not null,
|
|
|
|
primary key (help_category_id),
|
|
|
|
unique index (name)
|
|
|
|
) 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)
|
|
|
|
) comment='keyword-topic relation';
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS help_keyword (
|
|
|
|
help_keyword_id int unsigned not null,
|
|
|
|
name varchar(64) not null,
|
|
|
|
primary key (help_keyword_id),
|
|
|
|
unique index (name)
|
|
|
|
) comment='help keywords';
|
2003-10-22 16:10:22 +02:00
|
|
|
|
2003-10-01 16:50:50 +03:00
|
|
|
#
|
|
|
|
# Create proc table if it doesn't exists
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS proc (
|
2003-12-16 19:14:10 +01:00
|
|
|
db char(64) binary DEFAULT '' NOT NULL,
|
2004-03-23 12:04:40 +01:00
|
|
|
name char(64) DEFAULT '' NOT NULL,
|
2003-12-10 19:05:37 +01:00
|
|
|
type enum('FUNCTION','PROCEDURE') NOT NULL,
|
2004-03-23 12:04:40 +01:00
|
|
|
specific_name char(64) DEFAULT '' NOT NULL,
|
2003-12-10 19:05:37 +01:00
|
|
|
language enum('SQL') DEFAULT 'SQL' NOT NULL,
|
|
|
|
sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL,
|
|
|
|
is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL,
|
|
|
|
param_list blob DEFAULT '' NOT NULL,
|
|
|
|
returns char(64) DEFAULT '' NOT NULL,
|
|
|
|
body blob DEFAULT '' NOT NULL,
|
2003-12-10 19:05:37 +01:00
|
|
|
definer char(77) binary 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'
|
|
|
|
) DEFAULT 0 NOT NULL,
|
|
|
|
comment char(64) binary DEFAULT '' NOT NULL,
|
2003-12-16 19:14:10 +01:00
|
|
|
PRIMARY KEY (db,name,type)
|
2003-10-01 16:50:50 +03:00
|
|
|
) comment='Stored Procedures';
|
2004-03-23 12:04:40 +01:00
|
|
|
|
|
|
|
# Correct the name fields to not binary
|
|
|
|
ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL,
|
|
|
|
MODIFY specific_name char(64) DEFAULT '' NOT NULL;
|