if [ -f /etc/mysql/clusters.conf ]; then
MYSQL_DB_CLUSTERS=$(awk -F= '!/^#/ && /=/{print $2}' /etc/mysql/clusters.conf)
- if [ -z "$MYSQL_DB_CLUSTERS" ]; then
+ 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
+ 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
exit 0
fi
+sharedir=/usr/share/mysql
+
action="$1"
# any db cluster as command line argument?
fi
if [ "$mode" = "start" ]; then
- MYSQL_GREP_PID=$(grep -lE "^/usr/sbin/mysqld.*${MYSQL_PIDFILE}" /proc/[0-9]*/cmdline 2> /dev/null | awk -F "/" '{ print $3; exit; }')
+ MYSQL_GREP_PID=$(grep -alE "^/usr/sbin/mysqld.*${MYSQL_PIDFILE}" /proc/[0-9]*/cmdline 2> /dev/null | awk -F "/" '{ print $3; exit; }')
if [ -n "$MYSQL_GREP_PID" ]; then
MYSQL_PID=$MYSQL_GREP_PID
if grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline 2> /dev/null; then
--datadir=$MYSQL_DATA_DIR \
--pid-file=$MYSQL_PIDFILE \
${MYSQL_LOG_ERROR:+--log-error="$MYSQL_LOG_ERROR"} \
- $MYSQL_OPTIONS &
+ $MYSQL_OPTIONS 2>/dev/null &
pid=$!
sleep 0.1
# report slave status
# uses MYSQL_SOCKET - path to mysql socket
slave_status() {
+ if [ ! -x /usr/bin/mysql ]; then
+ echo >&2 "Slave status not available: 'mysql' program not installed."
+ return
+ fi
+
# see if slave status can be reported
local err=0 slave_status=$(mysql --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" -e 'show slave status\G')
if [ -z "$slave_status" ]; then
MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf"
fi
- show "Initializing cluster %s" "$clusterdir"; started
+ show "Initializing MySQL cluster %s" "$clusterdir"; started
# Check if not exist init database
if [ -d "$MYSQL_DATA_DIR/mysql" ]; then
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/percona-server/mysqld.conf -a ! -f "$MYSQL_CLUSTER_DIR/mysqld.conf" ]; then
- sed -e "
- s#\(datadir.*\)=.*#\1= $MYSQL_DATA_DIR#g;
- s#\(pid-file.*\)=.*#\1= $MYSQL_PIDFILE#g;
- s#\(socket.*\)=.*#\1= $MYSQL_SOCKET#g;
- s#@clusterdir@#$MYSQL_CLUSTER_DIR#g;
- " /usr/share/percona-server/mysqld.conf > "$MYSQL_CLUSTER_DIR/mysqld.conf"
- chown root:root "$MYSQL_CLUSTER_DIR/mysqld.conf"
- chmod 640 "$MYSQL_CLUSTER_DIR/mysqld.conf"
+ if [ -f $sharedir/mysqld.conf -a ! -f "$MYSQL_CLUSTER_DIR/mysqld.conf" ]; then
+ sed -e "
+ s#\(datadir.*\)=.*#\1= $MYSQL_DATA_DIR#g;
+ s#\(pid-file.*\)=.*#\1= $MYSQL_PIDFILE#g;
+ s#\(socket.*\)=.*#\1= $MYSQL_SOCKET#g;
+ s#@clusterdir@#$MYSQL_CLUSTER_DIR#g;
+ " $sharedir/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 ] || [ -L /var/lib/mysql/mysql.sock ] && [ -z "$(readlink /var/lib/mysql/mysql.sock)" ]; then
- sock=${MYSQL_SOCKET#/var/lib/mysql/} # make it relative if possible
- ln -s "$sock" /var/lib/mysql/mysql.sock
- fi
-
- cat > $MYSQL_DATA_DIR/mysql-init.sql <<-EOF
- CREATE DATABASE mysql;
- use mysql;
- $(cat /usr/share/percona-server/mysql_system_tables.sql)
- $(sed -e "/@current_hostname/d" /usr/share/percona-server/mysql_system_tables_data.sql)
-EOF
-
ok=0
/usr/sbin/mysqld \
--defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \
- --bootstrap \
+ --initialize-insecure \
--skip-grant-tables \
--datadir=$MYSQL_DATA_DIR \
--user=$MYSQL_USER \
--slave-load-tmpdir=$MYSQL_DATA_DIR \
--tmpdir=$MYSQL_DATA_DIR \
- --log-error=$MYSQL_ERRLOG \
- < $MYSQL_DATA_DIR/mysql-init.sql && ok=1
+ --log-error=$MYSQL_ERRLOG && ok=1
[ -f $MYSQL_DATA_DIR/mysql/user.frm ] || ok=0
if [ "$ok" = 1 ]; then
- rm -f $MYSQL_DATA_DIR/mysql-init.sql
ok
cat << END_OF_MSG
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS!
-This is done, after starting database, in the order shown,
+This is done, after starting database, in the order shown below,
with:
-For 'mysql_sysadmin' (RELOAD and SHUTDOWN privileges):
-echo "update mysql.user set password=password('newpassword') where user='mysql_sysadmin'; FLUSH PRIVILEGES;" | mysql -u mysql -S $MYSQL_SOCKET
+Add 'mysql_sysadmin' user (RELOAD and SHUTDOWN privileges):
+echo "CREATE USER 'mysql_sysadmin'@'localhost' IDENTIFIED BY 'SOME_RANDOM_PASSWORD'; FLUSH PRIVILEGES;" | mysql --ssl-mode=DISABLED -u root -S $MYSQL_SOCKET
+echo "GRANT RELOAD, SHUTDOWN ON *.* TO 'mysql_sysadmin'@'localhost'; FLUSH PRIVILEGES;" | mysql --ssl-mode=DISABLED -u root -S $MYSQL_SOCKET
-For 'mysql' user (ALL privileges, DB admin):
-echo "update mysql.user set password=password('newpassword') where user='mysql'; FLUSH PRIVILEGES;" | mysql -u mysql -S $MYSQL_SOCKET
+Set password for root user (ALL privileges, DB admin):
+echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'; FLUSH PRIVILEGES;" | mysql --ssl-mode=DISABLED -u root -S $MYSQL_SOCKET
NOTE: mysql_sysadmin password should be placed to $MYSQL_CONFIG in
mysqladmin section. See the manual for more instructions.
(This user is used at logs rotation and server shutdown)
END_OF_MSG
- show "Filling help tables..."
- ok=0
- ( echo "use mysql;"; cat /usr/share/percona-server/fill_help_tables.sql ) | \
- /usr/sbin/mysqld \
- --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \
- --bootstrap \
- --skip-grant-tables \
- --datadir=$MYSQL_DATA_DIR \
- --user=$MYSQL_USER \
- --slave-load-tmpdir=$MYSQL_DATA_DIR \
- --tmpdir=$MYSQL_DATA_DIR \
- --log-error=$MYSQL_ERRLOG \
- && ok=1
- if [ "$ok" = 1 ]; then
- ok
- else
- cat << END_OF_MSG
-
-WARNING: HELP FILES ARE NOT COMPLETELY INSTALLED!
-The "HELP" command might not work properly.
-
-END_OF_MSG
- fi
else
fail
cat << END_OF_MSG
ERROR:
ERROR:
-ERROR: Installation of grant tables FAILED!
+ERROR: Initialization of server FAILED!
ERROR:
ERROR:
-The initialization SQL script was preserved at $MYSQL_DATA_DIR/mysql-init.sql
-
-Examine the logs in /var/log/mysql for more information. You can
+Examine the logs in /var/log/mysql for more information. You can
also try to start the mysqld daemon with:
/usr/sbin/mysqld --skip-grant &
You can use the command line tool mysql to connect to the mysql
database and look at the grant tables:
-shell> mysql -u mysql mysql
+shell> mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Setting on
logging in $MYSQL_DATA_DIR/mysqld.conf gives you a log in /var/log/mysql/query.log that
may be helpful. The latest information about MySQL is available on the
-web at http://www.mysql.com/.
+web at https://www.percona.com/software/mysql-database/mysql.
-Please check PLD Linux ftp site for newer versions of this package.
+Please check TLD 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.
+your OS. Another information source is the MySQL email archive.
END_OF_MSG
exit 1
fi
+
+ # if it's first server, register as default
+ if [ ! -e /var/lib/mysql/mysql.sock ] || [ -L /var/lib/mysql/mysql.sock ] && [ -z "$(readlink /var/lib/mysql/mysql.sock)" ]; then
+ sock=${MYSQL_SOCKET#/var/lib/mysql/} # make it relative if possible
+ ln -s "$sock" /var/lib/mysql/mysql.sock
+ fi
+ # same for config, move to /etc
+ if [ ! -e /etc/mysql/mysqld.conf ]; then
+ mv "$MYSQL_CLUSTER_DIR/mysqld.conf" /etc/mysql/mysqld.conf
+ fi
}
#
;;
flush-logs)
for mysqldir in $DB_CLUSTERS; do
- mysqlgetconfig "$mysqldir"
+ 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