Key Words
- ERROR 1006 (HY000): Can’t create database
- Starting MySQL. The server quit without updating PID file
- The MySQL database directory permission is incorrect
The development environment
- CentOS Linux Release 7.5.1804 (Core)
- MySQL version: MySQL 5.6
Problem Scenario Description
In one case, I arbitrarily changed file/folder permissions and owners using the find and chown command lines, and later simply changed the WWW folder permissions back to 755[1] and the file permissions to 644; Owner all changed to root, at this time, an invisible big mine was personally buried by me.
When I created a new database in the database the next day, I found that whether I was a regular user of the database, or logged in as root, he seemed to jokingly tell me:
ERROR 1006 (HY000): Can't create database
I knew right away that something was wrong, that this must be a deep hole I had created. I copied the ERROR into the search engine and found that most of them said permissions, so I remembered what I had done and started looking for a way to restore the default permissions (unfortunately there was no backup), which led me to restart the mysqld service and, to my surprise, shutdown OK, Error: Start failed
Starting MySQL.The server quit without updating PID file
[Facepack][Facepack] I looked for the MySQL log and found that there was no error and that every subsequent restart was not recorded in the log.
It makes me feel like I’ve just fallen into a pit before I come out, and then I accidentally fall into another pit.
But fortunately persisted for a morning, until the afternoon, I found that the original is the same problem: MySQL data directory may have a permission problem. After you read the solution, maybe you will understand.
The solution
-
Open the/etc/my CNF
Find two messages in [mysqld] :
-
/ WWW /server/data = / WWW /server/data; / WWW /server/data = / WWW /server/data
-
Log-bin — this is where the log exists, but it is possible to see only log-bin=mysql-bin, where the default is not changed, mysql-bin is the datadir above.
-
-
First look at the error log
If you open it to your datadir folder, there is a ***. Err file. This is an error log for MySQL.
Here are the two key steps that lead to the above two problems:
- MySQL creates a ****. Pid file in DATADIR every time it starts the service. It will be deleted when it stops the service. I accidentally changed the owner of the entire folder (including the contents in the folder) to root, so MySQL does not have permission to create a new ****. Pid file, so I reported the second error.
- Why can’t I create a new database as user root when I can log in to MySQL? I guess it may be because the permission of my previous folder is 755 and the file is 644; The user group and the public group can read, but cannot write, so the first error is reported!
-
Owner of the modified Datadir
$ sudo chown -R mysql:mysql YOUR_DATADIR Copy the code
** Note: ** Remember to put YOUR_DATADIR where we just found datadir
-
Alter datadir file and folder permissions:
You are advised to set the permission of the database data directory to 700 and files to 660
-
Change folder permissions to 700:
$ sudo find YOUR_DATADIR -type d -exec chmod 700 {} \; Copy the code
-
Change the file permission to 660:
$ sudo find YOUR_DATADIR -type f -exec chmod 660 {} \; Copy the code
-
Restarting the MySQL service
At this point, we can try again
$ sudo /etc/init.d/mysqld restart Copy the code
If [OK] appears, you’re almost done!!
-
MySQL > alter database
mysql > create database 57EN; Query OK, 1 row affected Time: 0.001s Copy the code
It took me a long time, but it gave me a deeper understanding of MySQL, from just knowing how to use MySQL, to now knowing that the database starts from a service and it creates a.PID file (MySQL service process), It used to store data and logs in its DATADIR. I think it is necessary to have a deeper understanding of the log. When encountering problems, you can find problems through the log and solve the problems.
[1] Folder permissions 755:
In Linux, three types of operation objects (owner, user group, and public group) each have three permissions (read, write, and execute) on files or folders. The Linux system hopes to quickly know the permissions of the three types of operation objects based on the following numerical rules.
4 indicates the read permission, 2 indicates the write permission, and 1 indicates the execute permission.
7 = 4 + 2 + 1
Add the number of permissions for the same operation object, for example:
The permission of 755 represents that the owner has read/write and execute permissions. The user group has read and execute permissions. Common groups have read and execute permissions.
Personally test effective solutions, any questions you are welcome to leave a message.
— 57EN (December 26, 2018