6.3.3 mysql.server — MySQL Server Startup Script (original) (raw)

6.3.3 mysql.server — MySQL Server Startup Script

MySQL distributions on Unix and Unix-like system include a script named mysql.server, which starts the MySQL server using mysqld_safe. 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 is the script name as used within the MySQL source tree. The installed name might be different (for example, mysqld ormysql). In the following discussion, adjust the name mysql.server as appropriate for your system.

To start or stop the server manually using themysql.server script, invoke it from the command line with start orstop arguments:

mysql.server start
mysql.server stop

mysql.server changes location to the MySQL installation directory, then invokesmysqld_safe. 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 editmysql.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 runsmysqld_safe. If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future; make a copy of your edited version that you can reinstall.)

mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown.

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:

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 script:

chkconfig --level 345 mysql on  
/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'  

mysql.server 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 in a global /etc/my.cnf file. A typicalmy.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 options shown in the following table. If specified, they_must_ be placed in an option file, not on the command line. mysql.server supports onlystart and stop as command-line arguments.

Table 6.8 mysql.server Option-File Options

Option Name Description Type
basedir Path to MySQL installation directory Directory name
datadir Path to MySQL data directory Directory name
pid-file File in which server should write its process ID File name
service-startup-timeout How long to wait for server startup Integer