Starting/ Stopping MySQL
Starting MySQL:
- Run the mysqld binary directly.
- Run mysqld_safe.
- Run mysql.server with a parameter.
- Includes copies such as /etc/init.d/mysql
- Example (upstart/SysV init): service mysql start
- Example (systemd): systemctl start mysql
- Use systemctl command for MySQL rpm installation for systemd distribution :
- systemctl start mysqld
- On Windows, start by mysqld.exe
Stopping MySQL:
- Kill the mysqld binary with the SIGTERM signal (-15).
- Kill mysqld_safe first if it is running.
- Run mysql.server with the parameter value stop.
- service mysql stop
- systemctl stop mysql
- Use systemctl command for MySQL rpm installation for systemd distribution :
- systemctl stop mysqld
- Stopping MySQL with mysqladmin (client login path): mysqladmin shutdown
- Sometimes mysqladmin commands need root privileges to run, hence you can also use
- (shutdown with credential ) mysqladmin -u root -p -h dbhost -P 3306 shutdown
- (shutdown with admin login path) mysqladmin --login-path=mysql shutdown
Using kill
- The service mysql stop command (or systemctl stop mysql on systemd
- distributions) sends the UNIX SIGTERM signal (kill -15) to the mysqld process which the
- process interprets as an instruction to shut down the server.
- When you use mysqladmin to shutdown, it uses a server protocol command to send the “shut down” message to the server. In both cases, the server process receives the message and performs the same orderly shutdown procedure.
- If you send the SIGKILL signal (kill -9), mysqld shuts down immediately without an
- orderly shutdown, as if you had pulled the power cord on the machine. If the mysqld_safe
- helper program is running, it detects this sudden shutdown as a crash and restarts mysqld.
MySQL Availability- Status Check
mysqladmin -u root -p status
If DB is up, it will show uptime and number of queries, etc.
Uptime: 1408 Threads: 1 Questions: 35 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.024
else, the error as follows
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Ps -ef|grep mysqld