mysql_create_system_tables.sh 13.9 KB
Newer Older
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
1
#!/bin/sh
2
# Copyright (C) 1997-2003 MySQL AB
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
3 4 5 6 7 8 9 10 11 12 13
# For a more info consult the file COPYRIGHT distributed with this file

# This script writes on stdout SQL commands to generate all not
# existing MySQL system tables. It also replaces the help tables with
# new context from the manual (from fill_help_tables.sql).

# $1 - "test" or "real" or "verbose" variant of database
# $2 - path to mysql-database directory
# $3 - hostname  
# $4 - windows option

14
if test "$1" = ""
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
15 16 17 18 19 20 21
then
  echo "
This script writes on stdout SQL commands to generate all not
existing MySQL system tables. It also replaces the help tables with
new context from the manual (from fill_help_tables.sql).

Usage:
22 23 24
  mysql_create_system_tables [test|verbose|real] <path to mysql-database directory> <hostname> <windows option>
"
  exit
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fi

mdata=$2
hostname=$3
windows=$4

# Initialize variables
c_d="" i_d=""
c_h="" i_h=""
c_u="" i_u=""
c_f="" i_f=""
c_t="" c_c=""
c_ht=""
c_hc=""
c_hr="" 
c_hk="" 
i_ht=""
42
c_p=""
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
43 44 45 46

# Check for old tables
if test ! -f $mdata/db.frm
then
47
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    echo "Preparing db table" 1>&2; 
  fi

  # mysqld --bootstrap wants one command/line
  c_d="$c_d CREATE TABLE db ("
  c_d="$c_d   Host char(60) binary DEFAULT '' NOT NULL,"
  c_d="$c_d   Db char(64) binary DEFAULT '' NOT NULL,"
  c_d="$c_d   User char(16) binary DEFAULT '' NOT NULL,"
  c_d="$c_d   Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
68 69
  c_d="$c_d   Create_view_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_d="$c_d   Show_view_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
70 71 72 73 74
  c_d="$c_d PRIMARY KEY Host (Host,Db,User),"
  c_d="$c_d KEY User (User)"
  c_d="$c_d )"
  c_d="$c_d comment='Database privileges';"
  
75 76
  i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y');
  INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y');"
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
77 78 79 80
fi

if test ! -f $mdata/host.frm
then
81
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    echo "Preparing host table" 1>&2;
  fi

  c_h="$c_h CREATE TABLE host ("
  c_h="$c_h  Host char(60) binary DEFAULT '' NOT NULL,"
  c_h="$c_h  Db char(64) binary DEFAULT '' NOT NULL,"
  c_h="$c_h  Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
100 101
  c_h="$c_h  Create_view_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_h="$c_h  Show_view_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
102 103 104 105 106 107 108
  c_h="$c_h  PRIMARY KEY Host (Host,Db)"
  c_h="$c_h )"
  c_h="$c_h comment='Host privileges;  Merged with database privileges';"
fi

if test ! -f $mdata/user.frm
then
109
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
110 111 112 113 114 115
    echo "Preparing user table" 1>&2;
  fi

  c_u="$c_u CREATE TABLE user ("
  c_u="$c_u   Host char(60) binary DEFAULT '' NOT NULL,"
  c_u="$c_u   User char(16) binary DEFAULT '' NOT NULL,"
116
  c_u="$c_u   Password char(41) binary DEFAULT '' NOT NULL,"
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  c_u="$c_u   Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Process_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   File_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Super_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
138 139
  c_u="$c_u   Create_view_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  c_u="$c_u   Show_view_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
140 141 142 143 144 145 146 147 148 149 150
  c_u="$c_u   ssl_type enum('','ANY','X509', 'SPECIFIED') DEFAULT '' NOT NULL,"
  c_u="$c_u   ssl_cipher BLOB NOT NULL,"
  c_u="$c_u   x509_issuer BLOB NOT NULL,"
  c_u="$c_u   x509_subject BLOB NOT NULL,"
  c_u="$c_u   max_questions int(11) unsigned DEFAULT 0  NOT NULL,"
  c_u="$c_u   max_updates int(11) unsigned DEFAULT 0  NOT NULL,"
  c_u="$c_u   max_connections int(11) unsigned DEFAULT 0  NOT NULL,"
  c_u="$c_u   PRIMARY KEY Host (Host,User)"
  c_u="$c_u )"
  c_u="$c_u comment='Users and global privileges';"

151
  if test "$1" = "test" 
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
152
  then
153 154 155
    i_u="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','','','','',0,0,0);
    INSERT INTO user VALUES ('$hostname','root','','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);
    REPLACE INTO user VALUES ('127.0.0.1','root','','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);
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
156 157 158
    INSERT INTO user (host,user) values ('localhost','');
    INSERT INTO user (host,user) values ('$hostname','');"
  else
159
    i_u="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','','','','',0,0,0);"
160
    if test "$windows" = "0"
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
161 162
    then
      i_u="$i_u 
163
           INSERT INTO user VALUES ('$hostname','root','','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);
164 165
           INSERT INTO user (host,user) values ('$hostname','');
           INSERT INTO user (host,user) values ('localhost','');"
166
    else
167
      i_u="INSERT INTO user VALUES ('localhost','','','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);"
168
    fi
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
169 170 171 172 173
  fi 
fi

if test ! -f $mdata/func.frm
then
174
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    echo "Preparing func table" 1>&2;
  fi

  c_f="$c_f CREATE TABLE func ("
  c_f="$c_f   name char(64) binary DEFAULT '' NOT NULL,"
  c_f="$c_f   ret tinyint(1) DEFAULT '0' NOT NULL,"
  c_f="$c_f   dl char(128) DEFAULT '' NOT NULL,"
  c_f="$c_f   type enum ('function','aggregate') NOT NULL,"
  c_f="$c_f   PRIMARY KEY (name)"
  c_f="$c_f )"
  c_f="$c_f   comment='User defined functions';"
fi

if test ! -f $mdata/tables_priv.frm
then
190
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    echo "Preparing tables_priv table" 1>&2;
  fi

  c_t="$c_t CREATE TABLE tables_priv ("
  c_t="$c_t   Host char(60) binary DEFAULT '' NOT NULL,"
  c_t="$c_t   Db char(64) binary DEFAULT '' NOT NULL,"
  c_t="$c_t   User char(16) binary DEFAULT '' NOT NULL,"
  c_t="$c_t   Table_name char(60) binary DEFAULT '' NOT NULL,"
  c_t="$c_t   Grantor char(77) DEFAULT '' NOT NULL,"
  c_t="$c_t   Timestamp timestamp(14),"
  c_t="$c_t   Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,"
  c_t="$c_t   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
  c_t="$c_t   PRIMARY KEY (Host,Db,User,Table_name),"
  c_t="$c_t   KEY Grantor (Grantor)"
  c_t="$c_t )"
  c_t="$c_t   comment='Table privileges';"
fi

if test ! -f $mdata/columns_priv.frm
then
211
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    echo "Preparing columns_priv table" 1>&2;
  fi

  c_c="$c_c CREATE TABLE columns_priv ("
  c_c="$c_c   Host char(60) binary DEFAULT '' NOT NULL,"
  c_c="$c_c   Db char(64) binary DEFAULT '' NOT NULL,"
  c_c="$c_c   User char(16) binary DEFAULT '' NOT NULL,"
  c_c="$c_c   Table_name char(64) binary DEFAULT '' NOT NULL,"
  c_c="$c_c   Column_name char(64) binary DEFAULT '' NOT NULL,"
  c_c="$c_c   Timestamp timestamp(14),"
  c_c="$c_c   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
  c_c="$c_c   PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
  c_c="$c_c )"
  c_c="$c_c   comment='Column privileges';"
fi

if test ! -f $mdata/help_topic.frm
then
230
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    echo "Preparing help_topic table" 1>&2;
  fi

  c_ht="$c_ht CREATE TABLE help_topic ("
  c_ht="$c_ht   help_topic_id    int unsigned not null,"
  c_ht="$c_ht   name             varchar(64) not null,"
  c_ht="$c_ht   help_category_id smallint unsigned not null,"
  c_ht="$c_ht   description      text not null,"
  c_ht="$c_ht   example          text not null,"
  c_ht="$c_ht   url              varchar(128) not null,"
  c_ht="$c_ht   primary key      (help_topic_id),"
  c_ht="$c_ht   unique index     (name)"
  c_ht="$c_ht )"
  c_ht="$c_ht   comment='help topics';"
fi

old_categories="yes"
		    
if test ! -f $mdata/help_category.frm
then
251
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
    echo "Preparing help_category table" 1>&2;
  fi
  
  c_hc="$c_hc CREATE TABLE help_category ("
  c_hc="$c_hc   help_category_id   smallint unsigned not null,"
  c_hc="$c_hc   name               varchar(64) not null,"
  c_hc="$c_hc   parent_category_id smallint unsigned null,"
  c_hc="$c_hc   url                varchar(128) not null,"
  c_hc="$c_hc   primary key        (help_category_id),"
  c_hc="$c_hc   unique index       (name)"
  c_hc="$c_hc )"
  c_hc="$c_hc   comment='help categories';"
fi

if test ! -f $mdata/help_keyword.frm
then
268
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282
    echo "Preparing help_keyword table" 1>&2;
  fi

  c_hk="$c_hk CREATE TABLE help_keyword ("
  c_hk="$c_hk   help_keyword_id  int unsigned not null,"
  c_hk="$c_hk   name             varchar(64) not null,"
  c_hk="$c_hk   primary key      (help_keyword_id),"
  c_hk="$c_hk   unique index     (name)"
  c_hk="$c_hk )"
  c_hk="$c_hk   comment='help keywords';"
fi
				    
if test ! -f $mdata/help_relation.frm
then
283
  if test "$1" = "verbose" ; then
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
284 285 286 287 288 289 290 291 292 293 294
   echo "Preparing help_relation table" 1>&2;
  fi

  c_hr="$c_hr CREATE TABLE help_relation ("
  c_hr="$c_hr   help_topic_id    int unsigned not null references help_topic,"
  c_hr="$c_hr   help_keyword_id  int unsigned not null references help_keyword,"
  c_hr="$c_hr   primary key      (help_keyword_id, help_topic_id)"
  c_hr="$c_hr )"
  c_hr="$c_hr   comment='keyword-topic relation';"
fi

295 296 297
if test ! -f $mdata/proc.frm
then
  c_p="$c_p CREATE TABLE proc ("
298
  c_p="$c_p   db                char(64) binary DEFAULT '' NOT NULL,"
299 300 301 302 303 304
  c_p="$c_p   name              char(64) binary DEFAULT '' NOT NULL,"
  c_p="$c_p   type              enum('FUNCTION','PROCEDURE') NOT NULL,"
  c_p="$c_p   specific_name     char(64) binary DEFAULT '' NOT NULL,"
  c_p="$c_p   language          enum('SQL') DEFAULT 'SQL' NOT NULL,"
  c_p="$c_p   sql_data_access   enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL,"
  c_p="$c_p   is_deterministic  enum('YES','NO') DEFAULT 'NO' NOT NULL,"
305 306 307 308
  c_p="$c_p   security_type     enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL,"
  c_p="$c_p   param_list        blob DEFAULT '' NOT NULL,"
  c_p="$c_p   returns           char(64) DEFAULT '' NOT NULL,"
  c_p="$c_p   body              blob DEFAULT '' NOT NULL,"
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
  c_p="$c_p   definer           char(77) binary DEFAULT '' NOT NULL,"
  c_p="$c_p   created           timestamp,"
  c_p="$c_p   modified          timestamp,"
  c_p="$c_p   sql_mode          set("
  c_p="$c_p                         'REAL_AS_FLOAT',"
  c_p="$c_p                         'PIPES_AS_CONCAT',"
  c_p="$c_p                         'ANSI_QUOTES',"
  c_p="$c_p                         'IGNORE_SPACE',"
  c_p="$c_p                         'NOT_USED',"
  c_p="$c_p                         'ONLY_FULL_GROUP_BY',"
  c_p="$c_p                         'NO_UNSIGNED_SUBTRACTION',"
  c_p="$c_p                         'NO_DIR_IN_CREATE',"
  c_p="$c_p                         'POSTGRESQL',"
  c_p="$c_p                         'ORACLE',"
  c_p="$c_p                         'MSSQL',"
  c_p="$c_p                         'DB2',"
  c_p="$c_p                         'MAXDB',"
  c_p="$c_p                         'NO_KEY_OPTIONS',"
  c_p="$c_p                         'NO_TABLE_OPTIONS',"
  c_p="$c_p                         'NO_FIELD_OPTIONS',"
  c_p="$c_p                         'MYSQL323',"
  c_p="$c_p                         'MYSQL40',"
  c_p="$c_p                         'ANSI',"
  c_p="$c_p                         'NO_AUTO_VALUE_ON_ZERO'"
  c_p="$c_p                     ) DEFAULT 0 NOT NULL,"
  c_p="$c_p   comment           char(64) binary DEFAULT '' NOT NULL,"
335
  c_p="$c_p   PRIMARY KEY (db,name,type)"
336
  c_p="$c_p ) comment='Stored Procedures';"
337
fi
338

vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
cat << END_OF_DATA
use mysql;
$c_d
$i_d

$c_h
$i_h

$c_u
$i_u

$c_f
$i_f

$c_t
$c_c

$c_ht
$c_hc
$c_hr
$c_hk
360 361 362

$c_p

vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
363 364
END_OF_DATA