Security in MySQL  /  Postinstallation Setup and Testing  /  Starting and Stopping MySQL Automatically

3.5 Starting and Stopping MySQL Automatically

This section discusses methods for starting and stopping the MySQL server.

Generally, you start the mysqld server in one of these ways:

  • Invoke mysqld directly. This works on any platform.

  • On Windows, you can set up a MySQL service that runs automatically when Windows starts. See Starting MySQL as a Windows Service.

  • On Unix and Unix-like systems, you can invoke mysqld_safe, which tries to determine the proper options for mysqld and then runs it with those options. See mysqld_safe — MySQL Server Startup Script.

  • On Linux systems that support systemd, you can use it to control the server. See Managing MySQL Server with systemd.

  • On systems that use System V-style run directories (that is, /etc/init.d and run-level specific directories), invoke mysql.server. This script is used primarily at system startup and shutdown. It usually is installed under the name mysql. The mysql.server script starts the server by invoking mysqld_safe. See mysql.server — MySQL Server Startup Script.

  • On macOS, install a launchd daemon to enable automatic MySQL startup at system startup. The daemon starts the server by invoking mysqld_safe. For details, see Installing and Using the MySQL Launch Daemon. A MySQL Preference Pane also provides control for starting and stopping MySQL through the System Preferences. See Installing and Using the MySQL Preference Pane.

  • On Solaris, use the service management framework (SMF) system to initiate and control MySQL startup.

systemd, the mysqld_safe and mysql.server scripts, Solaris SMF, and the macOS Startup Item (or MySQL Preference Pane) can be used to start the server manually, or automatically at system startup time. systemd, mysql.server, and the Startup Item also can be used to stop the server.

The following table shows which option groups the server and startup scripts read from option files.

Table 3.1 MySQL Startup Scripts and Supported Server Option Groups

Script Option Groups
mysqld [mysqld], [server], [mysqld-major_version]
mysqld_safe [mysqld], [server], [mysqld_safe]
mysql.server [mysqld], [mysql.server], [server]

[mysqld-major_version] means that groups with names like [mysqld-5.7] and [mysqld-8.0] are read by servers having versions 5.7.x, 8.0.x, and so forth. This feature can be used to specify options that can be read only by servers within a given release series.

For backward compatibility, mysql.server also reads the [mysql_server] group and mysqld_safe also reads the [safe_mysqld] group. To be current, you should update your option files to use the [mysql.server] and [mysqld_safe] groups instead.

For more information on MySQL configuration files and their structure and contents, see Using Option Files.

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by dennis pickering on March 4, 2011
On Fedora 13, 3 yum installs were needed. The first two were not sufficient to load the normal init.d startup script. Third one did.

yum install mysql
yum install php-mysql
yum install mysql-server

Also. chkconfig is ok. ntsysv as a more interactive and visual.

  Posted by Morten Bjoernsvik on August 16, 2011
(V5.5.15 build from sources opensuse11.4)

I think the support-files/mysql.server needs to be rewritten. It is way to complex for just managing mysqld_safe

The documentation urge You to install as a non root user, but this script does not take --user into account, Even though you add user='mysql_test' to the my.conf file.

In order to start I need the following command:
/opt/mysql/bin/mysqld_safe --user='mysql_test' --datadir='/home/mysqldata' --basedir=/opt/mysql

I have to use
/etc/init.d/mysql.server start --user='mysql_test'
to get it to work. But it will not autostart

I just added a $user variable to the script and pushed it into the $mysql_safe command. then it works.

Sign Up Login You must be logged in to post a comment.