X-Git-Url: https://git.pld-linux.org/?a=blobdiff_plain;f=mysql.init;h=d4250d700ddbf9a1ae1de86c2ebf6b3167db5670;hb=b3f27e197120f172edb0848e4fe4a90d13f18788;hp=c3df1f9d6351203c2744aee02ff3ab6d3a82582f;hpb=f19b03aa291beb44f332320e6b78c8b01eef3215;p=packages%2Fmysql.git diff --git a/mysql.init b/mysql.init index c3df1f9..d4250d7 100644 --- a/mysql.init +++ b/mysql.init @@ -1,272 +1,652 @@ #!/bin/sh # -# mysql A very fast and reliable SQL database engine +# mysql A very fast and reliable SQL database engine # -# chkconfig: 2345 90 25 +# chkconfig: 2345 84 25 # -# description: A very fast and reliable SQL database engine. +# description: A very fast and reliable SQL database engine. # -# pidfile: /var/lib/mysql/mysqld.pid - # Source function library . /etc/rc.d/init.d/functions # Get network config . /etc/sysconfig/network -# Check that networking is up. -if is_no "${NETWORKING}"; then - msg_Network_Down MySQL - exit 1 -fi - -MYSQLD_ERRLOG=/var/log/mysql/err -MYSQLD_CONFIG=/etc/mysqld.conf - # Get service config -if [ -f /etc/sysconfig/mysql ] ; then +if [ -f /etc/sysconfig/mysql ]; then . /etc/sysconfig/mysql +else + nls "Error: %s not found" /etc/sysconfig/mysql + nls "%s can't be run." MySQL + exit 1 fi -# Daemon don't dies if config doesn't exists -if [ ! -f $MYSQLD_CONFIG ]; then - echo "MySQL config $MYSQLD_CONFIG not exists" - exit 1 +if [ -n "$MYSQL_DB_CLUSTERS" ]; then + nls "Warning: MYSQL_DB_CLUSTERS is set. It's obsolete. Use %s instead." /etc/mysql/clusters.conf fi -if [ ! -f $MYSQLD_CONFIG ]; then - echo "MySQL config $MYSQLD_CONFIG not exists" - exit 1 +if [ -f /etc/mysql/clusters.conf ]; then + MYSQL_DB_CLUSTERS=$(grep -v '^#' /etc/mysql/clusters.conf | cut -s -f 2 -d '=') + if [ -z "$MYSQL_DB_CLUSTERS" ]; then + nls "Warning: there are no configured clusters." + fi + +else + nls "Warning: Missing clusters config file %s" /etc/mysql/clusters.conf + if [ -z "$MYSQL_DB_CLUSTERS" ]; then + nls "Warning: there are no configured clusters." + nls "Using default cluster /var/lib/mysql (compatibility mode)" + MYSQL_DB_CLUSTERS=/var/lib/mysql + fi fi -MYSQL_DATA_DIR=`grep -m 1 "^[[:space:]]*datadir" $MYSQLD_CONFIG 2>/dev/null| cut -f 2 -d= | tr -d '[:space:]'` -MYSQL_USER=`grep -m 1 "^[[:space:]]*user" $MYSQLD_CONFIG 2>/dev/null| cut -f 2 -d= | tr -d '[:space:]'` -MYSQLD_PIDFILE=`grep -m 1 "^[[:space:]]*pid\-file" $MYSQLD_CONFIG 2>/dev/null| cut -f 2 -d= | tr -d '[:space:]'` -if [ -z $MYSQL_DATA_DIR ]; then - echo "MySQL datadir $MYSQL_DATA_DIR not configured propely!" - echo "Edit $MYSQLD_CONFIG and configure it." - exit 1 +# Check that networking is up +if is_yes "${NETWORKING}"; then + if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then + msg_network_down MySQL + exit 1 + fi +else + exit 0 fi -if [ -z $MYSQL_USER ]; then - echo "MySQL user not configured propely!" - echo "Edit $MYSQLD_CONFIG and configure it." - exit 1 +action="$1" + +# any db cluster as command line argument? +if [ $# -gt 1 ]; then + shift + # perform action for specified clusters only + DB_CLUSTERS="$@" +else + DB_CLUSTERS="$MYSQL_DB_CLUSTERS" fi +MYSQL_ERRLOG=/var/log/mysql/err -case "$1" in - start) - if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then - echo "MySQL database not initialized. Try \"$0 init\" before start." - exit 1 +# +# Useful functions. +# + +# +# check for mysql status +# +# arguments: +# $1 - db cluster +# +# sets variables: +# MYSQL_STATUS = running | not running | died +# MYSQL_PID = pid of mysqld process +# +mysqlstatus() { + clusterdir="$1" + mysqlgetconfig "$clusterdir" + + MYSQL_STATUS="not running" + MYSQL_PID="unknown" + + [ -f "$MYSQL_PIDFILE" ] && MYSQL_PID=$(cat "$MYSQL_PIDFILE") + + if [ ! -d "/proc/$MYSQL_PID" -a "$MYSQL_PID" != "unknown" ]; then + MYSQL_STATUS="died" + elif [ -d "/proc/$MYSQL_PID" ]; then + grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline && MYSQL_STATUS="running" || MYSQL_STATUS="not running" fi +} - # Check if the service is already running? - if [ -f /var/lock/subsys/mysql ]; then - msg_Already_Running MySQL - else - msg_starting MySQL - busy - - if [ ! -f $MYSQLD_ERRLOG ]; then - touch $MYSQLD_ERRLOG - fi - chown mysql.mysql $MYSQLD_ERRLOG - chmod 640 $MYSQLD_ERRLOG - - /usr/sbin/mysqld --defaults-file=$MYSQLD_CONFIG >>$MYSQLD_ERRLOG 2>&1 & - sleep 1 - deltext - if ps -C mysqld >/dev/null 2>&1; then - RETVAL=0 - ok +# get mysql configuration in variables +# MYSQL_CONFIG MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE +# +# arguments +# $1 - db cluster + +mysqlgetconfig() { + clusterdir="$1" + + # emulate old behaviour if only one cluster specified + if [ "$clusterdir" = "$MYSQL_DB_CLUSTERS" -a "$clusterdir" = "/var/lib/mysql" -a -f /etc/mysqld.conf ]; then + MYSQL_RA_COMPAT=yes; export MYSQL_RA_COMPAT + config_file=/etc/mysqld.conf + else + # TODO: convert this piece of crap to awk + config=`grep -v "^#" /etc/mysql/clusters.conf | grep "${clusterdir}$" | cut -s -f 1 -d '='` + if echo "$config" | grep -q '^/'; then + config_file="$config" + elif [ -f "/etc/mysql/$config" ]; then + config_file=/etc/mysql/$config else - RETVAL=1 - fail + config_file="$clusterdir/mysqld.conf" fi - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mysql fi - ;; - stop) - if [ -f /var/lock/subsys/mysql ]; then - msg_stopping MySQL - killproc mysqld - sleep 1 - rm -f /var/lock/subsys/mysql $MYSQLD_PIDFILE >/dev/null 2>&1 - else - msg_Not_Running MySQL - exit 1 - fi - ;; - status) - status mysqld - exit $? - ;; - restart|reload) - $0 stop - $0 start - ;; - init) + + MYSQL_CLUSTER_DIR="$clusterdir"; export MYSQL_CLUSTER_DIR + + if [ -z "$config_file" ]; then + nls "Error: Can't find config file for %s cluster" "$clusterdir" + exit 6 + else + MYSQL_CONFIG="$config_file"; export MYSQL_CONFIG + fi + + if [ ! -f "$config_file" ]; then + nls "Error: config file %s not found" "$config_file" + nls "MySQL can't be run. Did you initialize DB by doing \`$0 init'?" + exit 6 + fi + + eval `awk ' +/^[ \t]*\[.*\][ \t]*$/ { + match($0,/\[.*\]/) + section=substr($0,RSTART+1,RSTART+RLENGTH-3) +} +section=="mysqld" && $2~"=" { + if ($1=="datadir") { + printf("MYSQL_DATA_DIR=%s;", $3) + } else if ($1=="user") { + printf("MYSQL_USER=%s;", $3) + } else if ($1=="pid-file") { + printf("MYSQL_PIDFILE=%s;", $3) + } else if ($1=="socket") { + printf("MYSQL_SOCKET=%s;", $3) + } +} +END { + print "export MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE MYSQL_SOCKET" +} +' $config_file` + + + if is_yes "$MYSQL_RA_COMPAT"; then + MYSQL_DATA_DIR_SUB="" + else + MYSQL_DATA_DIR_SUB="/mysqldb" + fi + + if [ -z "$MYSQL_DATA_DIR" -o "$MYSQL_DATA_DIR" != "${clusterdir}${MYSQL_DATA_DIR_SUB}/db" ]; then + nls "Error: datadir specified in %s should be %s" "$config_file" "$clusterdir${MYSQL_DATA_DIR_SUB}/db" + nls " MySQL can't be run." + exit 6 + fi + + if [ -z "$MYSQL_PIDFILE" -o "$MYSQL_PIDFILE" != "$clusterdir${MYSQL_DATA_DIR_SUB}/mysql.pid" ]; then + nls "Error: pid-file specified in %s should be %s" "$config_file" "$clusterdir${MYSQL_DATA_DIR_SUB}/mysql.pid" + nls " MySQL can't be run." + exit 6 + fi + + if [ -z $MYSQL_USER ]; then + echo "$(nls 'MySQL user not configured properly')"'!' >&2 + nls "Edit %s and configure it." "$config_file" >&2 + exit 6 + fi +} + +# start mysql +mysqlstart() { + clusterdir="$1" + mysqlgetconfig "$clusterdir" + if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then + nls "MySQL cluster %s not initialized." "$clusterdir" + nls "Try \`%s init %s' before start." "$0" "$clusterdir" + exit 6 + fi + + msg_starting "MySQL $clusterdir" + busy + [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0 + TMPDIR=/tmp nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} /usr/bin/setsid /usr/sbin/mysqld --defaults-file=$MYSQL_CONFIG --datadir=$MYSQL_DATA_DIR --pid-file=$MYSQL_PIDFILE >> $MYSQL_ERRLOG 2>&1 & + sleep 2 + mysqlstatus "$clusterdir" + if [ "$MYSQL_STATUS" = "running" -a "$MYSQL_PID" != "unknown" ]; then + ok + elif [ "$MYSQL_STATUS" = "died" ]; then + RETVAL=1 + died + else + RETVAL=1 + fail + fi +} + +# stop mysql +mysqlstop() { + clusterdir="$1" + mysqlstatus "$clusterdir" + msg_stopping "MySQL $clusterdir" + busy + +# TODO +# graceful mysql shutdown with mysqladmin shutdown requires 'shutdown' +# privilege. create new user mysqlctl or rename mysql_logrotate to mysqlctl +# and give it both privs (flush-logs and shutdown)? + + # try graceful shutdown -- send shutdown command + /usr/bin/mysqladmin --defaults-file=$MYSQL_CONFIG ${MYSQL_SOCKET:+--socket=$MYSQL_SOCKET} shutdown >/dev/null 2>&1 + mysqlstatus "$clusterdir" + + [ "$MYSQL_PID" != "unknown" ] && kill -TERM "$MYSQL_PID" 2> /dev/null + # 3 seconds + for nr in 1 2 3; do + [ -d "/proc/$MYSQL_PID" ] && sleep 1 + done + mysqlstatus "$clusterdir" + if [ "$MYSQL_STATUS" = "died" ]; then + died + elif [ "$MYSQL_STATUS" = "running" ]; then + fail + else + ok + fi + + # FIXME: should let mysqld remove pid by itself? + rm -f "$MYSQL_PIDFILE" +} + +# +# check for running mysql instances; if any instance is running then +# create subsys lock file +# +mysqlsubsys() { + # check for every defined db cluster in sysconfig file + for mysqldir in $DB_CLUSTERS; do + mysqlstatus "$mysqldir" + if [ "$MYSQL_STATUS" = "running" ]; then + touch /var/lock/subsys/mysql + return + fi + done + rm -f /var/lock/subsys/mysql +} + +mysqlinit() { + clusterdir="$1" + + if [ -f /etc/mysqld.conf ]; then + nls "Running in \`no cluster compat' mode: can't initialize database." + nls "Move /etc/mysqld.conf away and rerun \`$0 init' (new config will be in $clusterdir)." + exit 1 + fi + + if [ -f "$clusterdir/mysqld.conf" ]; then + mysqlgetconfig "$clusterdir" + else + MYSQL_USER="mysql" + MYSQL_CLUSTER_DIR="$clusterdir" + MYSQL_DATA_DIR="$clusterdir/mysqldb/db" + MYSQL_PIDFILE="$clusterdir/mysqldb/mysql.pid" + MYSQL_SOCKET="$clusterdir/mysqldb/mysql.sock" + + # this $MYSQL_CONFIG will be created later + MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf" + fi + + nls "Initializing cluster %s" "$clusterdir" + # Check if not exist init database if [ -d "$MYSQL_DATA_DIR/mysql" ]; then - echo "Seems that database is initialized now. Remove by hand $MYSQL_DATA_DIR/mysql" - echo "before initialize database." - exit 1; + nls "Seems that database is initialized now. Remove by hand %s" "$MYSQL_DATA_DIR/mysql" + nls "before initializing database." + nls "For now skipping cluster %s." "$clusterdir" + return fi - show "Creating privilege mysql tables" + show "Creating privilege mysql tables for $MYSQL_DATA_DIR" busy - TMP=/tmp TMPDIR=/tmp - - # Install this too in the user table - hostname=`hostname --fqdn | tr -d '[:space:]'` - + TMP=/tmp TMPDIR=/tmp + + + # Install this in the user table, too + hostname="`hostname --fqdn 2> /dev/null | tr -d '[:space:]'`" + [ -z "$hostname" ] && hostname="localhost-unknown" + # Check if hostname is valid if [ -z "$hostname" ]; then deltext - fail - echo "Sorry, the host name is not configured." - echo "Please configure the 'hostname' command to return a hostname." + fail + nls "Sorry, the host name is not configured." + nls "Please configure the 'hostname' command to return a hostname." + exit 1 + elif ! hostname -i >/dev/null 2>&1; then + deltext + fail + nls "Sorry, the host '%s' could not be looked up." "$hostname" + nls "Please configure the 'hostname' command to return a correct hostname." exit 1 - elif ! hostname -i >/dev/null 2>&1; then - deltext - fail - echo "Sorry, the host '$hostname' could not be looked up." - echo "Please configure the 'hostname' command to return a correct hostname." - exit 1 - fi - - #mysqld --bootstrap need whole (and only one) sql command in one line - create_db="" - create_db="$create_db CREATE TABLE db ( " - create_db="$create_db Host char(60) DEFAULT '' NOT NULL, " - create_db="$create_db Db char(32) DEFAULT '' NOT NULL," - create_db="$create_db User char(16) DEFAULT '' NOT NULL, " - create_db="$create_db Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db References_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_db="$create_db PRIMARY KEY Host (Host,Db,User), " - create_db="$create_db KEY User (User)" - create_db="$create_db );" - - create_host="" - create_host="$create_host CREATE TABLE host ( " - create_host="$create_host Host char(60) DEFAULT '' NOT NULL, " - create_host="$create_host Db char(32) DEFAULT '' NOT NULL, " - create_host="$create_host Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host References_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_host="$create_host PRIMARY KEY Host (Host,Db)" - create_host="$create_host );" - - create_user="" - create_user="$create_user CREATE TABLE user (" - create_user="$create_user Host char(60) DEFAULT '' NOT NULL, " - create_user="$create_user User char(16) DEFAULT '' NOT NULL, " - create_user="$create_user Password char(16) DEFAULT '' NOT NULL, " - create_user="$create_user Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL," - create_user="$create_user Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL," - create_user="$create_user Process_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user File_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user References_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, " - create_user="$create_user PRIMARY KEY Host (Host,User)" - create_user="$create_user );" - - create_func="" - create_func="$create_func CREATE TABLE func ( " - create_func="$create_func name char(64) DEFAULT '' NOT NULL, " - create_func="$create_func ret tinyint(1) DEFAULT '0' NOT NULL," - create_func="$create_func dl char(128) DEFAULT '' NOT NULL, " - create_func="$create_func type enum ('function','aggregate') NOT NULL, " - create_func="$create_func PRIMARY KEY (name)" - create_func="$create_func ); " - - create_tblpriv="" - create_tblpriv="$create_tblpriv CREATE TABLE tables_priv ( " - create_tblpriv="$create_tblpriv Host char(60) DEFAULT '' NOT NULL, " - create_tblpriv="$create_tblpriv Db char(60) DEFAULT '' NOT NULL, " - create_tblpriv="$create_tblpriv User char(16) DEFAULT '' NOT NULL," - create_tblpriv="$create_tblpriv Table_name char(60) DEFAULT '' NOT NULL, " - create_tblpriv="$create_tblpriv Grantor char(77) DEFAULT '' NOT NULL, " - create_tblpriv="$create_tblpriv Timestamp timestamp(14), " - create_tblpriv="$create_tblpriv Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL, " - create_tblpriv="$create_tblpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," - create_tblpriv="$create_tblpriv PRIMARY KEY (Host,Db,User,Table_name), " - create_tblpriv="$create_tblpriv KEY Grantor (Grantor)" - create_tblpriv="$create_tblpriv );" - - create_colpriv="" - create_colpriv="$create_colpriv CREATE TABLE columns_priv ( " - create_colpriv="$create_colpriv Host char(60) DEFAULT '' NOT NULL, " - create_colpriv="$create_colpriv Db char(60) DEFAULT '' NOT NULL, " - create_colpriv="$create_colpriv User char(16) DEFAULT '' NOT NULL, " - create_colpriv="$create_colpriv Table_name char(60) DEFAULT '' NOT NULL, " - create_colpriv="$create_colpriv Column_name char(60) DEFAULT '' NOT NULL, " - create_colpriv="$create_colpriv Timestamp timestamp(14), " - create_colpriv="$create_colpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL, " - create_colpriv="$create_colpriv PRIMARY KEY (Host,Db,User,Table_name,Column_name)" - create_colpriv="$create_colpriv );" + fi + + # Initialize variables + c_d="" i_d="" c_ht="" c_tz="" + c_h="" i_h="" c_hc="" c_tzt="" + c_u="" i_u="" c_hk="" c_tztt="" + c_f="" i_f="" c_hr="" c_tzls="" + c_t="" c_c="" c_tzn="" + + # Check for old tables + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/db.frm + then + # mysqld --bootstrap wants one command/line + c_d="$c_d CREATE TABLE db (" + c_d="$c_d Host char(60) DEFAULT '' NOT NULL," + c_d="$c_d Db char(64) DEFAULT '' NOT NULL," + c_d="$c_d User char(16) 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," + 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 CHARACTER SET utf8 COLLATE utf8_bin" + c_d="$c_d comment='Database privileges';" + + i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); + INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');" + + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/host.frm + then + c_h="$c_h CREATE TABLE host (" + c_h="$c_h Host char(60) DEFAULT '' NOT NULL," + c_h="$c_h Db char(64) 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," + c_h="$c_h PRIMARY KEY Host (Host,Db)" + c_h="$c_h )" + c_h="$c_h CHARACTER SET utf8 COLLATE utf8_bin" + c_h="$c_h comment='Host privileges; Merged with database privileges';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/user.frm + then + c_u="$c_u CREATE TABLE user (" + c_u="$c_u Host char(60) DEFAULT '' NOT NULL," + c_u="$c_u User char(16) DEFAULT '' NOT NULL," + c_u="$c_u Password char(41) DEFAULT '' NOT NULL," + 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," + 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 CHARACTER SET utf8 COLLATE utf8_bin" + c_u="$c_u comment='Users and global privileges';" + + i_u="INSERT INTO user VALUES ('localhost','mysql','','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','mysql','','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 ('localhost','mysql','','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 ('$hostname','mysql','','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 ('localhost','mysql_logrotate','','N','N','N','N','N','N','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0);" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/func.frm + then + c_f="$c_f CREATE TABLE func (" + c_f="$c_f name char(64) 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 CHARACTER SET utf8 COLLATE utf8_bin" + c_f="$c_f comment='User defined functions';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/tables_priv.frm + then + c_t="$c_t CREATE TABLE tables_priv (" + c_t="$c_t Host char(60) DEFAULT '' NOT NULL," + c_t="$c_t Db char(64) DEFAULT '' NOT NULL," + c_t="$c_t User char(16) DEFAULT '' NOT NULL," + c_t="$c_t Table_name char(60) 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 CHARACTER SET utf8 COLLATE utf8_bin" + c_t="$c_t comment='Table privileges';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/columns_priv.frm + then + c_c="$c_c CREATE TABLE columns_priv (" + c_c="$c_c Host char(60) DEFAULT '' NOT NULL," + c_c="$c_c Db char(64) DEFAULT '' NOT NULL," + c_c="$c_c User char(16) DEFAULT '' NOT NULL," + c_c="$c_c Table_name char(64) DEFAULT '' NOT NULL," + c_c="$c_c Column_name char(64) 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 CHARACTER SET utf8 COLLATE utf8_bin" + c_c="$c_c comment='Column privileges';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_topic.frm + then + 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 CHARACTER SET utf8" + c_ht="$c_ht comment='help topics';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_category.frm + then + 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 CHARACTER SET utf8" + c_hc="$c_hc comment='help categories';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_keyword.frm + then + 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 CHARACTER SET utf8" + c_hk="$c_hk comment='help keywords';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_relation.frm + then + 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 CHARACTER SET utf8" + c_hr="$c_hr comment='keyword-topic relation';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_name.frm + then + c_tzn="$c_tzn CREATE TABLE time_zone_name (" + c_tzn="$c_tzn Name char(64) NOT NULL," + c_tzn="$c_tzn Time_zone_id int unsigned NOT NULL," + c_tzn="$c_tzn PRIMARY KEY Name (Name)" + c_tzn="$c_tzn )" + c_tzn="$c_tzn CHARACTER SET utf8" + c_tzn="$c_tzn comment='Time zone names';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone.frm + then + c_tz="$c_tz CREATE TABLE time_zone (" + c_tz="$c_tz Time_zone_id int unsigned NOT NULL auto_increment," + c_tz="$c_tz Use_leap_seconds enum('Y','N') DEFAULT 'N' NOT NULL," + c_tz="$c_tz PRIMARY KEY TzId (Time_zone_id)" + c_tz="$c_tz )" + c_tz="$c_tz CHARACTER SET utf8" + c_tz="$c_tz comment='Time zones';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_transition.frm + then + c_tzt="$c_tzt CREATE TABLE time_zone_transition (" + c_tzt="$c_tzt Time_zone_id int unsigned NOT NULL," + c_tzt="$c_tzt Transition_time bigint signed NOT NULL," + c_tzt="$c_tzt Transition_type_id int unsigned NOT NULL," + c_tzt="$c_tzt PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time)" + c_tzt="$c_tzt )" + c_tzt="$c_tzt CHARACTER SET utf8" + c_tzt="$c_tzt comment='Time zone transitions';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_transition_type.frm + then + c_tztt="$c_tztt CREATE TABLE time_zone_transition_type (" + c_tztt="$c_tztt Time_zone_id int unsigned NOT NULL," + c_tztt="$c_tztt Transition_type_id int unsigned NOT NULL," + c_tztt="$c_tztt Offset int signed DEFAULT 0 NOT NULL," + c_tztt="$c_tztt Is_DST tinyint unsigned DEFAULT 0 NOT NULL," + c_tztt="$c_tztt Abbreviation char(8) DEFAULT '' NOT NULL," + c_tztt="$c_tztt PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id)" + c_tztt="$c_tztt )" + c_tztt="$c_tztt CHARACTER SET utf8" + c_tztt="$c_tztt comment='Time zone transition types';" + fi + + if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_leap_second.frm + then + c_tzls="$c_tzls CREATE TABLE time_zone_leap_second (" + c_tzls="$c_tzls Transition_time bigint signed NOT NULL," + c_tzls="$c_tzls Correction int signed NOT NULL," + c_tzls="$c_tzls PRIMARY KEY TranTime (Transition_time)" + c_tzls="$c_tzls )" + c_tzls="$c_tzls CHARACTER SET utf8" + c_tzls="$c_tzls comment='Leap seconds information for time zones';" + fi + + mkdir -p "$MYSQL_DATA_DIR" > /dev/null 2>&1 + # Using mysql:mysql for MYSQL_CLUSTER_DIR is creating SECURITY hole, root:root is proper + chown root:root "$MYSQL_CLUSTER_DIR" + chown mysql:mysql "$MYSQL_CLUSTER_DIR/mysqldb" "$MYSQL_DATA_DIR" > /dev/null 2>&1 + chmod 751 "$MYSQL_CLUSTER_DIR" "$MYSQL_CLUSTER_DIR/mysqldb" + + if [ -f /usr/share/mysql/mysqld.conf -a ! -f "$MYSQL_CLUSTER_DIR/mysqld.conf" ]; then + sed -e "s#datadir.*=.*#datadir = $MYSQL_DATA_DIR#g" \ + -e "s#pid-file.*=.*#pid-file = $MYSQL_PIDFILE#g" \ + -e "s#socket.*=.*#socket = $MYSQL_SOCKET#g" \ + /usr/share/mysql/mysqld.conf > "$MYSQL_CLUSTER_DIR/mysqld.conf" + chown root:root "$MYSQL_CLUSTER_DIR/mysqld.conf" + chmod 640 "$MYSQL_CLUSTER_DIR/mysqld.conf" + fi + + if [ ! -e /var/lib/mysql/mysql.sock ]; then + ln -s "$MYSQL_SOCKET" /var/lib/mysql/mysql.sock + fi + if /usr/sbin/mysqld --bootstrap --skip-grant-tables \ - --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA -CREATE DATABASE mysql; + --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA +CREATE DATABASE mysql; use mysql; -$create_db -$inser_db -$create_host -$create_user -$insert_user -$create_func -$create_tblpriv -$create_colpriv -#INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y'); -#INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y'); -INSERT INTO user VALUES ('localhost','mysql_logrotate','','N','N','N','N','N','N','Y','N','N','N','N','N','N','N'); -INSERT INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); -INSERT INTO user VALUES ('$hostname','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); -REPLACE INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); -REPLACE INTO user VALUES ('$hostname','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); -END_OF_DATA +$c_d +$i_d + +$c_h +$i_h + +$c_u +$i_u + +$c_f +$i_f + +$c_t +$c_c - then - deltext +$c_ht +$c_hc +$c_hk +$c_hr + +$c_tzn +$c_tz +$c_tzt +$c_tztt +$c_tzls +END_OF_DATA + then ok - cat << END_OF_MSG -PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS!" -This is done with: -/usr/bin/mysqladmin -u mysql password 'password' -/usr/bin/mysqladmin -h $hostname -u mysql password 'password' -/usr/bin/mysqladmin -u mysql_logrotate password 'password' -NOTE: mysql_logrotate password should be placed to /etc/mysqld.conf in mysqladmin section -See the manual for more instructions. + cat << END_OF_MSG + +PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS! +This is done (after starting database) with: + +/usr/bin/mysqladmin -u mysql -S $MYSQL_SOCKET password 'password' +/usr/bin/mysqladmin -h $hostname -u mysql -S $MYSQL_SOCKET password 'password' +/usr/bin/mysqladmin -u mysql_logrotate -S $MYSQL_SOCKET password 'password' + +NOTE: mysql_logrotate password should be placed to $MYSQL_CONFIG in +mysqladmin section. See the manual for more instructions. END_OF_MSG - else - deltext + else fail cat << END_OF_MSG Installation of grant tables FAILED! @@ -285,26 +665,89 @@ mysql> show tables Try 'mysqld --help' if you have problems with paths. Setting on logging in /etc/mysqld.conf gives you a log in /var/log/mysql/log that may be helpful. The latest information about MySQL is available on the -web at . +web at http://www.mysql.com/. -Please check PLD ftp site for newer versions of this package. +Please check PLD Linux ftp site for newer versions of this package. Please consult the MySQL manual section: 'Problems running mysql_install_db', and the manual section that describes problems on your OS. Another information source is the MySQL email archive. Please check all of the above before mailing us! And if you do mail -us, you MUST use the /usr/bin/mysqlbug script! +us, you MUST use the /usr/bin/mysqlbug script! END_OF_MSG - exit 1 - fi + exit 1 + fi +} +# +# End of useful functions. +# + +RETVAL=0 +case "$action" in + start) + if [ ! -f $MYSQL_ERRLOG ]; then + touch $MYSQL_ERRLOG + fi + chown mysql:mysql $MYSQL_ERRLOG + chmod 640 $MYSQL_ERRLOG + + for mysqldir in $DB_CLUSTERS; do + mysqlstatus "$mysqldir" + if [ "$MYSQL_STATUS" = "running" ]; then + msg_already_running "MySQL $mysqldir" + else + mysqlstart "$mysqldir" + fi + done + mysqlsubsys ;; - *) - msg_Usage "$0 {start|stop|status|restart|reload|init}" - exit 1 + stop) + for mysqldir in $DB_CLUSTERS; do + mysqlstatus "$mysqldir" + if [ "$MYSQL_STATUS" = "not running" ]; then + msg_not_running "MySQL $mysqldir" + else + mysqlstop "$mysqldir" + fi + done + mysqlsubsys + ;; + status) + status mysqld + for mysqldir in $DB_CLUSTERS; do + mysqlstatus "$mysqldir" + echo "MySQL cluster $mysqldir: $MYSQL_STATUS" + done + exit $? ;; + restart|force-reload) + $0 stop $DB_CLUSTERS + $0 start $DB_CLUSTERS + exit $? + ;; + init) + for mysqldir in $DB_CLUSTERS; do + mysqlinit "$mysqldir" + done + exit $? + ;; + flush-logs) + for mysqldir in $DB_CLUSTERS; do + mysqlgetconfig "$mysqldir" + # just if mysqld is really running + if /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" ping >/dev/null 2>&1; then + /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" flush-logs + fi + done + ;; + *) + msg_usage "$0 {start|stop|init|restart|force-reload|status}" + exit 3 esac exit $RETVAL + +# vi: shiftwidth=4 tabstop=4