5 kx #!/bin/sh
5 kx # Start/stop/restart mysqld.
5 kx #
5 kx # Copyright 2003 Patrick J. Volkerding, Concord, CA
5 kx # Copyright 2003 Slackware Linux, Inc., Concord, CA
5 kx # Copyright 2008, 2013 Patrick J. Volkerding, Sebeka, MN, USA
5 kx #
5 kx # This program comes with NO WARRANTY, to the extent permitted by law.
5 kx # You may redistribute copies of this program under the terms of the
5 kx # GNU General Public License.
5 kx
5 kx # To start MariaDB automatically at boot, be sure this script is executable:
5 kx # chmod 755 /etc/rc.d/rc.mysqld
5 kx
5 kx # Before you can run MariaDB, you must have a database. To install an initial
5 kx # database, do this as root:
5 kx #
5 kx # mysql_install_db --user=mysql
5 kx #
5 kx # Note that the mysql user must exist in /etc/passwd, and the created files
5 kx # will be owned by this dedicated user. This is important, or else mysql
5 kx # (which runs as user "mysql") will not be able to write to the database
5 kx # later (this can be fixed with 'chown -R mysql.mysql /var/lib/mysql').
5 kx #
5 kx # To increase system security, consider using "mysql_secure_installation"
5 kx # as well. For more information on this tool, please read:
5 kx # man mysql_secure_installation
5 kx
5 kx # To allow outside connections to the database comment out the next line.
5 kx # If you don't need incoming network connections, then leave the line
5 kx # uncommented to improve system security.
5 kx SKIP="--skip-networking"
5 kx
5 kx # Start mysqld:
5 kx mysqld_start() {
5 kx if [ -x /usr/bin/mysqld_safe ]; then
5 kx # If there is an old PID file (no mysqld running), clean it up:
5 kx if [ -r /var/run/mysql/mysql.pid ]; then
5 kx if ! ps axc | grep mysqld 1> /dev/null 2> /dev/null ; then
5 kx echo "Cleaning up old /var/run/mysql/mysql.pid."
5 kx rm -f /var/run/mysql/mysql.pid
5 kx fi
5 kx fi
5 kx
5 kx /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysql/mysql.pid $SKIP &
5 kx fi
5 kx }
5 kx
5 kx # Stop mysqld:
5 kx mysqld_stop() {
5 kx # If there is no PID file, ignore this request...
5 kx if [ -r /var/run/mysql/mysql.pid ]; then
5 kx PID=$(cat /var/run/mysql/mysql.pid)
5 kx kill $PID
5 kx # Wait at least one minute for it to exit, as we don't know how big the DB is...
5 kx for second in $(seq 0 60) ; do
5 kx if [ ! -r /var/run/mysql/mysql.pid ]; then
5 kx break;
5 kx fi
5 kx sleep 1
5 kx done
5 kx if [ "$second" = "60" ]; then
5 kx echo "WARNING: Gave up waiting for mysqld to exit!"
5 kx sleep 15
5 kx fi
5 kx fi
5 kx }
5 kx
5 kx # Restart mysqld:
5 kx mysqld_restart() {
5 kx mysqld_stop
5 kx mysqld_start
5 kx }
5 kx
5 kx case "$1" in
5 kx 'start')
5 kx mysqld_start
5 kx ;;
5 kx 'stop')
5 kx mysqld_stop
5 kx ;;
5 kx 'restart')
5 kx mysqld_restart
5 kx ;;
5 kx *)
5 kx echo "usage $0 start|stop|restart"
5 kx esac