What to do if you can't start or stop MySQL

Hello, this is Goto from the Web Systems Division

previouslyan article about socket errors...wrote

that one solution for when the socket file is missing is to
restart the MySQL server, which will restore it.

However, there are cases like this

  • "MySQL manager or server PID file could not be found!"
    I can't stop it because I get the error
  • MySQL is not running, but lock exists
    , and it fails to start.

There may be things like this

This time I'll be taking note of the causes of these errors and how to deal with them

1. If you can't stop

The MySQL manager or server PID file could not be found!
This is because the PID file does not exist or cannot be found.

*A PID file is a file that records the Process ID.
In Linux, the kernel manages processes using something called a process identifier. This is the 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.
You can find various pid files by looking under /var/run/.

The solution is to create a PID file.
Check the location where you want to create it in 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 the 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 the PID

ps aux | grep mysqld

Next, let's check the PID of mysqld (not mysqld_safe).
fde69d1de836ef30f76004ce86430966-600x45
In this case, the PID of mysqld is 2846, so we write 2846 to the mysqld.pid file we created.

echo 2846 > /var/run/mysqld/mysql.pid

This should stop it!

2. If you can't start the game

MySQL is not running, but lock exists

The reason is that a lock file remains

*A lock file is a file created when a process successfully starts and deleted when a process successfully stops,
preventing the creation of duplicate processes.

The solution is to delete the lock file

# rm /var/lock/subsys/mysql

It should now start!

*Note: The same error may occur in the following cases:

  • /etc/my.cnf specifies that the log should be output to a directory that does not exist
  • No permissions for the destination directory

The above is what to do if you cannot start or stop MySQL

If you found this article helpful,please give it a "Like"!
0
Loading...
0 votes, average: 0.00 / 10
15,594
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author