mysql_fix_privilege_tables.sh
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. #!/bin/sh
  2. echo "This scripts updates the mysql.user, mysql.db, mysql.host and the"
  3. echo "mysql.func table to MySQL 3.22.14 and above."
  4. echo ""
  5. echo "This is needed if you want to use the new GRANT functions or"
  6. echo "want to use the more secure passwords."
  7. echo ""
  8. echo "If you get Access denied errors, you should run this script again"
  9. echo "and give the MySQL root user password as a argument!"
  10. root_password="$1"
  11. host="localhost"
  12. # Fix old password format, add File_priv and func table
  13. echo ""
  14. echo "If your tables are already up to date or partially up to date you will"
  15. echo "get some warnings about 'Duplicated column name' or"
  16. echo "'Table 'func' already exists'. You can safely ignore these!"
  17. @bindir@/mysql -f --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
  18. alter table user change password password char(16) NOT NULL;
  19. alter table user add File_priv enum('N','Y') NOT NULL;
  20. CREATE TABLE func (
  21.   name char(64) DEFAULT '' NOT NULL,
  22.   ret tinyint(1) DEFAULT '0' NOT NULL,
  23.   dl char(128) DEFAULT '' NOT NULL,
  24.   type enum ('function','aggregate') NOT NULL,
  25.   PRIMARY KEY (name)
  26. );
  27. END_OF_DATA
  28. echo ""
  29. # Add the new grant colums
  30. echo "Creating Grant Alter and Index privileges if they don't exists"
  31. echo "You can ignore any Duplicate column errors"
  32. @bindir@/mysql --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
  33. 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;
  34. 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;
  35. 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;
  36. END_OF_DATA
  37. res=$?
  38. echo ""
  39. # If the new grant columns didn't exists, copy File -> Grant
  40. # and Create -> Alter, Index, References
  41. if test $res = 0
  42. then
  43.   echo "Setting default privileges for the new grant, index and alter privileges"
  44.   @bindir@/mysql --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
  45.   UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  46.   UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  47.   UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
  48. END_OF_DATA
  49.   echo ""
  50. fi
  51. #
  52. # Create tables_priv and columns_priv if they don't exists
  53. #
  54. echo "Creating the new table and column privilege tables"
  55. @bindir@/mysql -f --user=root --password="$root_password"  --host="$host" mysql <<END_OF_DATA
  56. CREATE TABLE tables_priv (
  57.   Host char(60) DEFAULT '' NOT NULL,
  58.   Db char(60) DEFAULT '' NOT NULL,
  59.   User char(16) DEFAULT '' NOT NULL,
  60.   Table_name char(60) DEFAULT '' NOT NULL,
  61.   Grantor char(77) DEFAULT '' NOT NULL,
  62.   Timestamp timestamp(14),
  63.   Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,
  64.   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
  65.   PRIMARY KEY (Host,Db,User,Table_name)
  66. );
  67. CREATE TABLE columns_priv (
  68.   Host char(60) DEFAULT '' NOT NULL,
  69.   Db char(60) DEFAULT '' NOT NULL,
  70.   User char(16) DEFAULT '' NOT NULL,
  71.   Table_name char(60) DEFAULT '' NOT NULL,
  72.   Column_name char(59) DEFAULT '' NOT NULL,
  73.   Timestamp timestamp(14),
  74.   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
  75.   PRIMARY KEY (Host,Db,User,Table_name,Column_name)
  76. );
  77. END_OF_DATA
  78. #
  79. # Name change of Type -> Column_priv from MySQL 3.22.12
  80. #
  81. echo "Changing name of columns_priv.Type -> columns_priv.Column_priv"
  82. echo "You can ignore any errors from this"
  83. @bindir@/mysql -f --user=root --password="$root_password"  --host="$host" mysql <<END_OF_DATA
  84. ALTER TABLE columns_priv change Type Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL;
  85. END_OF_DATA
  86. #
  87. # Add the new 'type' column to the func table.
  88. #
  89. echo "Fixing the func table"
  90. echo "You can ignore any Duplicate column errors"
  91. @bindir@/mysql --user=root --password=$root_password mysql <<EOF
  92. alter table func add type enum ('function','aggregate') NOT NULL;
  93. EOF