ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

error message:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Cause of the problem:

It is possible that the [mysqld] parameter socket is set in the my.cnf configuration file, but the [client] parameter socket is not set.

What is the mysql.sock file used for:

mysql supports both socket and TCP/IP connections. So what is the use of the mysql.sock file? Connections to localhost are usually made through a Unix domain socket file, typically /tmp/mysql.sock. If the socket file is deleted, local clients will not be able to connect. The /tmp folder is a temporary file and may be deleted at any time.

1. TCP connection (if an error message is displayed for /tmp/mysql.sock, you can try this method to connect)

mysql -uroot -h 127.0.0.1 -p

2.Socket connection

mysql -uroot -p

Solution:

Add the [client] configuration item as shown below

Before configuration: (Before configuring [client], an error message will be reported: '/tmp/mysql.sock' (2))

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

After configuration: (After configuring [client], restart the mysql service)

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock (same as the socket path)
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
port=3306
socket=/var/lib/mysql/mysql.sock

end, this article ends, I hope it will be helpful to everyone!

You may also be interested in:
  • MySQL bypasses granting information_schema objects and reports ERROR 1044 (4200) error
  • mysql databasemysql: [ERROR] unknown option ''--skip-grant-tables''
  • How to solve the 10060 unknow error when Navicat remotely connects to MySQL
  • Ubuntu 18.0.4 installs mysql and solves ERROR 1698 (28000): Access denied for user ''''root''''@''''localhost'''
  • Solution to MySQL server login error ERROR 1820 (HY000)
  • Solve MySQL startup error: ERROR 2003 (HY000): Can't connect to MySQL server on ''localhost'' (10061)

<<:  Tutorial on deploying multiple servers with WebApi and configuring Nginx load balancing

>>:  Vue uses WebSocket to simulate the chat function

Recommend

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Native js implements custom scroll bar component

This article example shares the specific code of ...

How to uninstall MySQL 5.7.19 under Linux

1. Find out whether MySQL was installed before Co...

Implementation of Portals and Error Boundary Handling in React

Table of contents Portals Error Boundary Handling...

Detailed explanation of Navicat's slow remote connection to MySQL

The final solution is in the last picture If you ...

Quickjs encapsulates JavaScript sandbox details

Table of contents 1. Scenario 2. Simplify the und...

Three ways to implement text color gradient in CSS

In the process of web front-end development, UI d...

Analysis of the causes of accidents caused by Unicode signature BOM

Maybe you are using include files here, which is u...

How to use Linux locate command

01. Command Overview The locate command is actual...

Use Navicate to connect to MySQL on Alibaba Cloud Server

1. First enter the server's mysql to modify p...

Python 3.7 installation tutorial for MacBook

The detailed process of installing python3.7.0 on...