System: centos5.x
Previously, when I installed MySQL, the command for creating a user was as follows:
Shell> groupadd MySQL
Shell> useradd-G MySQL
Shell> Cd/usr/local
When you view/etc/passwd, the record is as follows:
MySQL: X: 501: 502:/home/MySQL:/bin/bash
From the above records, we can see that MySQL is a common user (UID 500 + ).
Check the Home Directory of MySQL:
Drwx ------ 2 MySQL 4096 Apr 15 MySQL
Well, there is no problem switching from the root user to MySQL. So I have never encountered any problems in this step. Next, let me talk about the problems encountered in this step.
If you carefully observe MySQL Manual (2.2. Installing MySQL from generic binaries on Unix/Linux), you will find that its operation command is as follows:
Shell> groupadd MySQL
Shell> useradd-r-g MySQL
Shell> Cd/usr/local
Its useradd adds an option '-R', which means "Create System Account ". The UID of MySQL in/etc/passwd can reflect this point:
MySQL: X: 101: 502:/home/MySQL:/bin/bash
After the user is created, the root switch to MySQL operation may occur unexpectedly:
# Su-MySQL
Su: Warning: cannot change directory to/home/MySQL: insufficient Permissions
-Bash:/home/MySQL/. bash_profile: insufficient Permissions
-Bash-3.2 $
In my opinion, "Permission denied" is not displayed in the root switch operation under normal circumstances. Why? By querying some information on the Internet, there is a saying that the user's permissions have encountered problems. For more information, see here. But this is not the reason. Through observation, the problem is shown here:
Drwx ------ 2 504 MySQL 4096 APR 29 MySQL
The problem of incorrect owner identity is well solved:
# Chown-r MySQL/
Cause analysis: the cause of the above primary identity problem is actually very simple, that is, when a new MySQL user (system UID) is created, it uses the Home Directory of a common MySQL user (using userdel to delete an old account with the same name without the '-R' option to keep its home directory. In this case, when the UID is inconsistent (the main identifier of the home directory is not updated by the system), and the user of this uid does not exist in the system, therefore, "Permission denied" occurs when the root user switches to the user ".