Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.9Mb
PDF (A4) - 37.9Mb
PDF (RPM) - 32.8Mb
HTML Download (TGZ) - 8.0Mb
HTML Download (Zip) - 8.1Mb
HTML Download (RPM) - 6.9Mb
Man Pages (TGZ) - 132.7Kb
Man Pages (Zip) - 189.0Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  /  ...  /  Starting and Stopping MySQL Automatically

2.9.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:

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 2.14 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 Section 4.2.6, “Using Option Files”.

User Comments
  Posted by on July 29, 2003
Remember that on FreeBSD or any *nix system that supports running scripts from /usr/local/etc/rc.d
you should do for security purposes:
#chmod 100 *
  Posted by Steven Casey on September 9, 2003
Running Mandrake Linux 9.1/MySQL 4.x: Following the instructions for auto-start didn't work. Drove me crazy until I created the startup symbolic link in the rc5.d instead of rc3.d.

If you need to boot without graphics or just level 3, then put the symbolic link to mysql.server in rc3.d
  Posted by Mongo Mongoson on March 26, 2004
Slackware 8 MySQL 4 autostart instructions:

I installed MySQL 4.0.18 on Slackware v8. The "auto-start" instructions don't seem to apply to Slackware. I ended up adding this to my /etc/rc.d/rc.M:

# Start MySQL server:
if [ -x /etc/rc.d/rc.mysql ]; then
. /etc/rc.d/rc.mysql start

then I added this to /etc/rc.d/rc.K above the #Kill all processes line:

# Shut down the MySQL database server
if [ -x /etc/rc.d/rc.mysql ]; then
. /etc/rc.d/rc.mysql stop

Then I created the /etc/rc.d/rc.mysql script:

# Start the MySQL database server

case "$1" in
/usr/local/mysql/support-files/mysql.server start ;;
/usr/local/mysql/support-files/mysql.server stop ;;
/usr/local/mysql/support-files/mysql.server restart ;;
echo "usage $0 start|stop|restart" ;;

That got me going and seems to work fine. If there's a real pro out there who knows a nicer/more correct way please let me know at -- Jon Reed

  Posted by Gabriel Barazer on October 12, 2004
I run a linux 2.6 server with only MySQL running (P4 3.2Ghz / 2GB) and sometimes (mainly when the server has run for a little time ,when it has reached an uptime of...30 minutes to few days), it becomes impossible to stop it with the right signal, or with mysqladmin (mysqladmin shutdown, or mysql.server stop). Mysql.server says it gaves up waiting and mysqladmin freeze too. nothing helpful in the error log, and finally i have to send a KILL signal to stop it. I've got this problem with all mysql 4 & 4.1 versions...

So to avoid a reboot failure (if the mysql.server script doesn't stop mysqld), it's better to add a kill command (which send SIGKILL to mysqld) in the mysql.server script after the waiting loop.
  Posted by on December 11, 2005
On Slackware 10, just copy mysql.server to /etc/rc.d and rename it to rc.mysqld

cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/rc.mysqld
  Posted by Wade Smith on January 19, 2006
On FreeBSD 5.x according to the file installed automatically with the ports collection for 4.1.16, you have to add the line in your rc.conf to have automatic startup for mysqld:


Don't know if this helps but I had to make the connect during post port installation to get mine to always come up without manual intervention.

  Posted by Sergio Tam on June 5, 2006
En FreeBsd para arrancar mysql después de instalarlo
editar el archivo /etc/rc.conf y agregar las siguiente linea mysql_enable="YES"
y después en la consola terminal ejecutas el siguiente comando /usr/local/etc/rc.d/ start,
si lo haces todo en este orden no tendrás problemas para iniciar el servidor.
Si no agregas la linea en el rc.conf y ejecutas el siguiente comando /usr/local/etc/rc.d/ start
te marcara el siguiente error Connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/temp/mysql.sock' exists!
  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.