All Products
Search
Document Center

When logging on to MySQL through the Socket, the system prompts that the "/var/lib/mysql/mysql.sock" file cannot be connected.

Last Updated: Dec 29, 2020

Problem description

You cannot log on by running the mysql -uroot-P command on the server and an error message appears.

Can't connect to local MySql server through socket '/var/lib/mysql/mysql.sock'

Cause

The Socket file path is specified during MySQL installation. The Socket file path is not the default /var/lib/mysql/mysql.sock.

Solution

Alibaba Cloud reminds you that:

  • Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
  • You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.
  • If you have authorized or submitted sensitive information such as the logon account and password in the Alibaba Cloud Management Console, we recommend that you modify such information in a timely manner.

Please use the following to specify the Socket file path.

mysql -s /tmp/mysql.sock -uroot -p

Scope

  • Elastic Compute Service
  • Simple Application Server