How to Start/Stop MySQL Server on Linux and Windows
Starting the MySQL Server on Linux
The server can be started from a command line:
# service mysql start
Starting the server follows this progression:
The server can be started on Linux using several methods:
- mysql.server: Used as a wrapper around mysqld_safefor systems such as Linux and Oracle Solaris that are using System V run-level directories
- mysqld_safe: Sets up the error log and then launches mysqld and monitors it. If mysqldterminates abnormally, mysqld_safe restarts it. If the server does not start properly, look in the error log.
- mysqld: Invokes the server manually to debug the MySQL server. The error messages go to the terminal by default rather than to the error log.
- mysqld_multi: Perl script that is intended to simplify the management of multiple servers on a single host. It can start or stop servers, or it can report whether servers are running.
Install the correct script to have the server run automatically at startup: - On BSD-style Linux systems, it is most common to invoke mysqld_safe from one of the system startup scripts, such as the rc.local script in the /etc directory. - Linux and UNIX System V variants with run-level directories under /etc/init.d use the mysql.server script. Pre-built Linux binary packages install mysql.server under the name mysql for the appropriate run levels. Invoke it manually with an argument of start or stop, either directly or by using the service command.
Stopping the MySQL Server on Linux
Methods for stopping the server:
|mysqladmin||Connects to the server as a client to shut down the server (local or remote)|
|mysql.server||Stops and/or shuts down the local server|
|mysqld_multi||Invokes mysqladmin to stop and/or shut down servers that it manages|
Stop the server from command line:
# service mysql stop
Check whether the server is running or not:
# service mysql status
To stop the server manually, use one of the following techniques:
- mysqladmin:Has a shutdown command. It connects to the server as a client and can shut down local or remote servers.
- mysql.server:Stops and/or shuts down the local server when invoked with an argument of stop
- mysqld_multi:Stops and/or shuts down any of the servers that it manages. It does so by invoking mysqladmin
mysqld_safe has no server shutdown capability. You can use mysqladmin shutdown instead. Note that if you forcibly terminate mysqld by using the ‘kill -9’ command to send it a signal, then mysqld_safedetects that mysqld terminated abnormally and restarts it. You can work around this by killing mysqld_safefirst and then killing mysqld, but it is better to use mysqladmin shutdown, which initiates a normal (clean) server shutdown.
Running MySQL on Windows
Methods for Running MySQL on Windows:
- Start manually - Stop manually
- Install manually - Start/stop manually or automatically - Use GUI
Run a Windows MySQL server manually from the command line of a console window by using the mysqld command (with extra options, if needed). You stop the server by using the mysqladmin shutdown command.
To run the MySQL server so that Windows itself starts and stops the server when Windows starts and stops, install the server as a Windows service. To do this, invoke the server from the command line using the mysqld –install command (with extra options if needed).
You can also start and stop the service manually from the command line by using the net start MySQL and net stop MySQL commands.
To start and stop the service by using the Windows Services GUI, select the MySQL service in the Administrative Tools and then click the Start or Stop link. You can configure manual or automatic startup in the Services GUI. To remove the service after it has been stopped, use mysqld with the –remove option.