### 4.3.3 mysql.server — MySQL Server Startup Script

[]()

 MySQL distributions on Unix and Unix-like system include a script named [**mysql.server**](mysql-server.html), which starts the MySQL server using [**mysqld\_safe**](mysqld-safe.html). It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the macOS Startup Item for MySQL.

[**mysql.server**](mysql-server.html) is the script name as used within the MySQL source tree. The installed name might be different (for example, [**mysqld**](mysqld.html) or [**mysql**](mysql.html)). In the following discussion, adjust the name [**mysql.server**](mysql-server.html) as appropriate for your system.

Note

 For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, [**mysql.server**](mysql-server.html) and [**mysqld\_safe**](mysqld-safe.html) are not installed because they are unnecessary. For more information, see [Section 2.5.9, “Managing MySQL Server with systemd”](using-systemd.html).

 To start or stop the server manually using the [**mysql.server**](mysql-server.html) script, invoke it from the command line with `start` or `stop` arguments:

```
mysql.server start
mysql.server stop
```

[**mysql.server**](mysql-server.html) changes location to the MySQL installation directory, then invokes [**mysqld\_safe**](mysqld-safe.html). To run the server as some specific user, add an appropriate `user` option to the `[mysqld]` group of the global `/etc/my.cnf` option file, as shown later in this section. (It is possible that you must edit [**mysql.server**](mysql-server.html) 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**](mysqld-safe.html). If you do this, your modified version of [**mysql.server**](mysql-server.html) may be overwritten if you upgrade MySQL in the future; make a copy of your edited version that you can reinstall.)

[**mysql.server stop**](mysql-server.html) stops the server by sending a signal to it. You can also stop the server manually by executing [**mysqladmin shutdown**](mysqladmin.html).

 To start and stop MySQL automatically on your server, you must add start and stop commands to the appropriate places in your `/etc/rc*` files:

* If you use the Linux server RPM package (`MySQL-server-*`VERSION`*.rpm`), or a native Linux package installation, the [**mysql.server**](mysql-server.html) script may be installed in the `/etc/init.d` directory with the name `mysqld` or `mysql`. See [Section 2.5.4, “Installing MySQL on Linux Using RPM Packages from Oracle”](linux-installation-rpm.html), for more information on the Linux RPM packages.

* If you install MySQL from a source distribution or using a binary distribution format that does not install [**mysql.server**](mysql-server.html) automatically, you can install the script manually. It can be found in the `support-files` directory under the MySQL installation directory or in a MySQL source tree. Copy the script to the `/etc/init.d` directory with the name [**mysql**](mysql.html) and make it executable:

  ```
  cp mysql.server /etc/init.d/mysql
  chmod +x /etc/init.d/mysql
  ```

   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**](mysql.html) script:

  ```
  chkconfig --level 345 mysql on
  ```

* On FreeBSD, startup scripts generally should go in `/usr/local/etc/rc.d/`. Install the `mysql.server` script as `/usr/local/etc/rc.d/mysql.server.sh` to enable automatic startup. The `rc(8)` manual page states that scripts in this directory are executed only if their base name matches the `*.sh` shell file name pattern. Any other files or directories present within the directory are silently ignored.

* As an alternative to the preceding setup, some operating systems also use `/etc/rc.local` or `/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.

[**mysql.server**](mysql-server.html) reads options from the `[mysql.server]` and `[mysqld]` sections of option files. For backward compatibility, it also reads `[mysql_server]` sections, but to be current you should rename such sections to `[mysql.server]`.

[]()

 You can add options for [**mysql.server**](mysql-server.html) in a global `/etc/my.cnf` file. A typical `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**](mysql-server.html) script supports the options shown in the following table. If specified, they *must* be placed in an option file, not on the command line. [**mysql.server**](mysql-server.html) supports only `start` and `stop` as command-line arguments.

[]()

**Table 4.7 mysql.server Option-File Options**

|                                       Option Name                                        |                  Description                   |     Type     |
|------------------------------------------------------------------------------------------|------------------------------------------------|--------------|
|                [`basedir`](mysql-server.html#option_mysql_server_basedir)                |      Path to MySQL installation directory      |Directory name|
|                [`datadir`](mysql-server.html#option_mysql_server_datadir)                |          Path to MySQL data directory          |Directory name|
|               [`pid-file`](mysql-server.html#option_mysql_server_pid-file)               |File in which server should write its process ID|  File name   |
|[`service-startup-timeout`](mysql-server.html#option_mysql_server_service-startup-timeout)|      How long to wait for server startup       |   Integer    |

* []() [`basedir=*`dir_name`*`](mysql-server.html#option_mysql_server_basedir)

  []()[]()

   The path to the MySQL installation directory.

* []() [`datadir=*`dir_name`*`](mysql-server.html#option_mysql_server_datadir)

  []()[]()

   The path to the MySQL data directory.

* []() [`pid-file=*`file_name`*`](mysql-server.html#option_mysql_server_pid-file)

  []()[]()

   The path name of the file in which the server should write its process ID. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.

   If this option is not given, [**mysql.server**](mysql-server.html) uses a default value of `*`host_name`*.pid`. The PID file value passed to [**mysqld\_safe**](mysqld-safe.html) overrides any value specified in the `[mysqld_safe]` option file group. Because [**mysql.server**](mysql-server.html) reads the `[mysqld]` option file group but not the `[mysqld_safe]` group, you can ensure that [**mysqld\_safe**](mysqld-safe.html) gets the same value when invoked from [**mysql.server**](mysql-server.html) as when invoked manually by putting the same `pid-file` setting in both the `[mysqld_safe]` and `[mysqld]` groups.

* []() [`service-startup-timeout=*`seconds`*`](mysql-server.html#option_mysql_server_service-startup-timeout)

  []()[]()

   How long in seconds to wait for confirmation of server startup. If the server does not start within this time, [**mysql.server**](mysql-server.html) exits with an error. The default value is 900. A value of 0 means not to wait at all for startup. Negative values mean to wait forever (no timeout).

