This section discusses how to start and stop 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 Section 220.127.116.11, “Starting MySQL as a Windows Service”.
On Unix and Unix-like systems, you can invoke Invoke mysqld_safe, which tries to determine the proper options for mysqld and then runs it with those options. See Section 4.3.2, “mysqld_safe — MySQL Server Startup Script”.
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
The mysql.server script starts the server
by invoking mysqld_safe. See
Section 4.3.3, “mysql.server — MySQL Server Startup Script”.
On OS X, install a separate MySQL Startup Item package to enable the automatic startup of MySQL on system startup. The Startup Item starts the server by invoking mysql.server. See Section 2.11, “Installing MySQL on OS X”, for details.
The mysqld_safe and mysql.server scripts and the OS X Startup Item can be used to start the server manually, or automatically at system startup time. mysql.server and the Startup Item also can be used to stop the server.
To start or stop the server manually using the
mysql.server script, invoke it with
Before mysql.server starts the server, it
changes location to the MySQL installation directory, and then
invokes mysqld_safe. If you want the server to
run as some specific user, add an appropriate
user option to the
group of the
/etc/my.cnf option file, as
shown later in this section. (It is possible that you must edit
mysql.server if you've installed a binary
distribution of MySQL in a nonstandard location. Modify it to
change location into the proper directory before it runs
mysqld_safe. If you do this, your modified
version of mysql.server may be overwritten if
you upgrade MySQL in the future, so you should make a copy of your
edited version that you can reinstall.)
To start and stop MySQL automatically on your server, you must add
start and stop commands to the appropriate places in your
If you use the Linux server RPM package
the mysql.server script is installed in the
/etc/init.d directory with the name
mysql. You need not install it manually. See
Section 2.12, “Installing MySQL on Linux Using RPM Packages”, for more information on
the Linux RPM packages.
Some vendors provide RPM packages that install a startup script under a different name such as mysqld.
If you install MySQL from a source distribution or using a binary
distribution format that does not install
mysql.server automatically, you can install it
manually. The script can be found in the
support-files directory under the MySQL
installation directory or in a MySQL source tree.
cp mysql.server /etc/init.d/mysqlshell>
chmod +x /etc/init.d/mysql
Older Red Hat systems use the
/etc/rc.d/init.d directory rather than
/etc/init.d. Adjust the preceding commands
accordingly. Alternatively, first create
/etc/init.d as a symbolic link that points
ln -s rc.d/init.d .
After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig:
chkconfig --add mysql
On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:
chkconfig --level 345 mysql on
On FreeBSD, startup scripts generally should go in
rc(8) manual page states that scripts in this
directory are executed only if their basename matches the
*.sh shell file name pattern. Any other files
or directories present within the directory are silently ignored.
In other words, on FreeBSD, you should install the
mysql.server script as
/usr/local/etc/rc.d/mysql.server.sh to enable
As an alternative to the preceding setup, some operating systems
/etc/init.d/boot.local to start additional
services on startup. To start up MySQL using this method, append a
command like the one following to the appropriate startup file:
/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
For other systems, consult your operating system documentation to see how to install startup scripts.
You can add options for mysql.server in a
/etc/my.cnf file. A typical
/etc/my.cnf file might look like this:
[mysqld] datadir=/usr/local/mysql/var socket=/var/tmp/mysql.sock port=3306 user=mysql [mysql.server] basedir=/usr/local/mysql
The mysql.server script supports the following
pid-file. If specified, they
must be placed in an option file, not on the
command line. mysql.server supports only
The following table shows which option groups the server and each startup script read from option files.
Table 2.8 MySQL Startup scripts and supported server option groups
means that groups with names like
[mysqld-5.0] are read by servers
having versions 4.1.x, 5.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
[mysql_server] group and
mysqld_safe also reads the
[safe_mysqld] group. However, you should update
your option files to use the
[mysqld_safe] groups instead.
For more information on MySQL configuration files and their structure and contents, see Section 4.2.6, “Using Option Files”.