home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / Software / Resources / MySQL / Windows / data1.cab / Development / scripts / mysql_fix_privilege_tables.sql < prev    next >
Encoding:
Text File  |  2003-10-20  |  5.9 KB  |  160 lines

  1. -- This scripts updates the mysql.user, mysql.db, mysql.host and the
  2. -- mysql.func tables to MySQL 3.22.14 and above.
  3.  
  4. -- This is needed if you want to use the new GRANT functions,
  5. -- CREATE AGGREGATE FUNCTION or want to use the more secure passwords in 3.23
  6.  
  7. -- If you get 'Access denied' errors, you should run this script again
  8. -- and give the MySQL root user password as an argument!
  9.  
  10.  
  11. -- Converting all privilege tables to MyISAM format
  12. ALTER TABLE user type=MyISAM;
  13. ALTER TABLE db type=MyISAM;
  14. ALTER TABLE host type=MyISAM;
  15. ALTER TABLE func type=MyISAM;
  16. ALTER TABLE columns_priv type=MyISAM;
  17. ALTER TABLE tables_priv type=MyISAM;
  18.  
  19.  
  20. --  Fix old password format, add File_priv and func table
  21.  
  22. -- If your tables are already up to date or partially up to date you will
  23. -- get some warnings about 'Duplicated column name'. You can safely ignore these!
  24.  
  25. alter table user change password password char(16) NOT NULL;
  26. alter table user add File_priv enum('N','Y') NOT NULL;
  27. CREATE TABLE if not exists func (
  28.   name char(64) DEFAULT '' NOT NULL,
  29.   ret tinyint(1) DEFAULT '0' NOT NULL,
  30.   dl char(128) DEFAULT '' NOT NULL,
  31.   type enum ('function','aggregate') NOT NULL,
  32.   PRIMARY KEY (name)
  33. );
  34.  
  35. --  Add the new grant colums
  36.  
  37. -- Creating Grant Alter and Index privileges if they don't exists
  38. -- You can ignore any Duplicate column errors
  39. 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;
  40. 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;
  41. 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;
  42.  
  43. --  If the new grant columns didn't exists, copy File -> Grant
  44. --  and Create -> Alter, Index, References
  45.  
  46. -- Setting default privileges for the new grant, index and alter privileges
  47.   UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  48.   UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  49.   UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  50.  
  51. --
  52. --  The second alter changes ssl_type to new 4.0.2 format
  53.  
  54. -- Adding columns needed by GRANT .. REQUIRE (openssl)"
  55. -- You can ignore any Duplicate column errors"
  56. ALTER TABLE user
  57. ADD ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL,
  58. ADD ssl_cipher BLOB NOT NULL,
  59. ADD x509_issuer BLOB NOT NULL,
  60. ADD x509_subject BLOB NOT NULL;
  61. ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL;
  62.  
  63. --
  64. --  Create tables_priv and columns_priv if they don't exists
  65. --
  66.  
  67. -- Creating the new table and column privilege tables"
  68.  
  69. CREATE TABLE IF NOT EXISTS tables_priv (
  70.   Host char(60) DEFAULT '' NOT NULL,
  71.   Db char(60) DEFAULT '' NOT NULL,
  72.   User char(16) DEFAULT '' NOT NULL,
  73.   Table_name char(60) DEFAULT '' NOT NULL,
  74.   Grantor char(77) DEFAULT '' NOT NULL,
  75.   Timestamp timestamp(14),
  76.   Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,
  77.   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
  78.   PRIMARY KEY (Host,Db,User,Table_name)
  79. );
  80. CREATE TABLE IF NOT EXISTS columns_priv (
  81.   Host char(60) DEFAULT '' NOT NULL,
  82.   Db char(60) DEFAULT '' NOT NULL,
  83.   User char(16) DEFAULT '' NOT NULL,
  84.   Table_name char(60) DEFAULT '' NOT NULL,
  85.   Column_name char(59) DEFAULT '' NOT NULL,
  86.   Timestamp timestamp(14),
  87.   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
  88.   PRIMARY KEY (Host,Db,User,Table_name,Column_name)
  89. );
  90.  
  91. --
  92. --  Name change of Type -> Column_priv from MySQL 3.22.12
  93. --
  94.  
  95. -- Changing name of columns_priv.Type -> columns_priv.Column_priv
  96. -- You can ignore any Unknown column errors from this
  97.  
  98.  
  99. ALTER TABLE columns_priv change Type Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL;
  100.  
  101.  
  102.  
  103. --
  104. --  Add the new 'type' column to the func table.
  105. --
  106.  
  107. -- Fixing the func table
  108. -- You can ignore any Duplicate column errors
  109.  
  110. alter table func add type enum ('function','aggregate') NOT NULL;
  111.  
  112.  
  113. --
  114. --  Change the user,db and host tables to MySQL 4.0 format
  115. --
  116.  
  117. -- Adding new fields used by MySQL 4.0.2 to the privilege tables
  118. -- You can ignore any Duplicate column errors
  119.  
  120.  
  121. alter table user
  122. add Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER alter_priv,
  123. add Super_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Show_db_priv,
  124. add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Super_priv,
  125. add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Create_tmp_table_priv,
  126. add Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Lock_tables_priv,
  127. add Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Execute_priv,
  128. add Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Repl_slave_priv;
  129.  
  130.  
  131. -- Convert privileges so that users have similar privileges as before
  132.  
  133. -- Updating new privileges in MySQL 4.0.2 from old ones
  134.  
  135.   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<>"";
  136.  
  137.  
  138. --  Add fields that can be used to limit number of questions and connections
  139. --  for some users.
  140.  
  141.  
  142. alter table user
  143. add max_questions int(11) NOT NULL AFTER x509_subject,
  144. add max_updates   int(11) unsigned NOT NULL AFTER max_questions,
  145. add max_connections int(11) unsigned NOT NULL AFTER max_updates;
  146.  
  147.  
  148. --
  149. --  Add Create_tmp_table_priv and Lock_tables_priv to db and host
  150. --
  151.  
  152.  
  153. alter table db
  154. add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,
  155. add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
  156. alter table host
  157. add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,
  158. add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
  159.  
  160.