What to do if you cannot start or stop MySQL
Hello. My name is Goto from the Web Systems Division.
previously wrote an article about socket errors
I wrote that one of the solutions when the socket file does not exist is
However, there are cases like this.
- MySQL manager or server PID file could not be found!
appears and cannot be stopped. - MySQL is not running, but lock exists
and cannot start.
There may be something like that.
This time, I will write down the causes of these errors and how to deal with them.
1. If you can't stop it
MySQL manager or server PID file could not be found!
This is because the PID file does not exist or cannot be found.
*PID file is a file in which PID is written.
In Linux, the kernel manages processes using process identifiers. This is PID (Process ID).
For processes that are directly started by the system, such as mysqld, a pid file is generated so that the kernel does not forget it.
If you look under /var/run/, you will see various pid files.
The workaround is to create a PID file.
Check the location to create from my.cnf.
/etc/my.cnf
pid-file = /var/run/mysqld/mysqld.pid
It is set to be installed in /var/run/mysqld/mysqld.pid, so create a PID file there.
# touch /var/run/mysqld/mysql.pid # chown mysql:mysql /var/run/mysqld/mysqld.pid
The contents of the PID file must contain a PID.
ps aux | grep mysqld
Let's check the PID of mysqld (not mysqld_safe).
In this case, 2846 is the PID of mysqld, so write 2846 to the created mysqld.pid.
echo 2846 > /var/run/mysqld/mysql.pid
This should stop it!
2. If you cannot start
MySQL is not running, but lock exists
The cause is that the lock file remains.
*A lock file is a file that is created when a process is successfully started and deleted when the process is successfully stopped,
to prevent the same process from being created twice.
The solution is to delete the lock file.
# rm /var/lock/subsys/mysql
You should now be able to boot!
*Note: The same error seems to occur in the following cases.
- /etc/my.cnf specifies that logs be output to a directory that does not exist.
- There are no permissions on the output destination directory
The above is what to do when you cannot start or stop MySQL.