centos 7 登陆 mysql 报错:Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (111)

Error report

        After installing mysql 8.0.31 using the source code on the centos 7 machine, enter the initial password, and report the following error:

        According to the error, enter the /usr/local/mysql3306/data/ directory (the /usr/local/mysql3306/ directory is the installation directory of mysql 8.0.31), and found that there is indeed no mysql.sock file, /usr/local/mysql3306/ The content of the data/ directory is as follows:

Internet search situation 

        According to the error problem, I searched on the Internet, and most of the solutions point to: need to make a soft connection to mysql.sock;

soft link

ln -s /data/mysql/tmp/mysql.sock /tmp/mysql.sock

illustrate:

       /usr/local/mysql3306/data/mysql.sock is the installation directory of mysql3306;

       /tmp/mysql.sock system file;

soft link result

The result shows that the soft connection cannot be created, and the result is as follows:

To no avail! !

final solution

        There are many reasons why an error is reported after entering the initial password: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111);

        But most of them are because some key steps were missed in the process of installing mysql!

my situation

        I use the source code to deploy mysql 8.0.31 on centos 7. After the installation is complete and the initial password is entered, the above error is reported! ! !

        After careful inspection, I finally found out: I forgot to create a user name and group 

      (In this case, you may have forgotten to create a username and group, or you may have missed some other important steps, so consider reviewing the installation process!)

Solution

 1. There is no need to delete the installed mysql, and directly create user accounts and groups on the existing basis. The creation command is as follows:

# 参数说明:-M 不创建家目录 -s 指定 -r 创建系统账户

groupadd mysql3306 
useradd -r -g mysql3306 -M -s /bin/false mysql3306 

 
# 因为我在一台机器上部署了多个 mysql 
# 为了加以区分,所以创建的用户名和组都以端口号命名,如: mysql3306 

 2. Then clear all the content in the /usr/local/mysql3306/data/ directory, and clear the command as follows;

cd /usr/local/mysql3306/data/
rm -rf *

Note: Before reinitialization, the ./data folder in the mysql installation directory must be cleared, otherwise reinitialization will fail

3. Reinitialize, the initialization command is as follows:

# --defaults-file=/etc/my3306.cnf 中的 /etc/my3306.cnf 为自己创建的配置文件名称和路径
# --user=mysql3306 中的 mysql3306 为用户名,需要和上述创建的保持一致
# --port=3306 中的 3306 为端口号,该命令是初始化指定端口号的 mysql

bin/mysqld --defaults-file=/etc/my3306.cnf --initialize --user=mysql3306 --port=3306

4. After the initialization is complete, start mysql and enter the initial password. The command to start mysql is as follows:

# 启动指定端口号的 mysql

bin/mysqld_safe --user=mysql3306 --port=3306 &

bin/mysql -u root -p -P 3306

 The execution result is as follows:

Guess you like

Origin blog.csdn.net/weixin_47156401/article/details/132134763