ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
时间: 2023-10-14 16:29:36 浏览: 122
This error message typically indicates that the MySQL server is not running or is not configured to accept connections from the local machine. Here are some steps that you can follow to troubleshoot the issue:
1. Verify that the MySQL server is running: Check if the MySQL server is running by typing the following command in a terminal or command prompt:
```
systemctl status mysql
```
If the command returns an error message or indicates that the service is not running, try starting the service using the following command:
```
sudo systemctl start mysql
```
If the service fails to start, you may need to check the MySQL error logs for more information.
2. Check if the MySQL server is configured to accept local connections: Open the MySQL configuration file (usually located at /etc/mysql/mysql.conf.d/mysqld.cnf) and look for the following line:
```
bind-address = 127.0.0.1
```
If the line is commented out or set to a different IP address, modify it to match the loopback address (127.0.0.1). Save the file and restart the MySQL service.
3. Check if there are any firewall rules blocking the MySQL port (usually 3306): Use the following command to check if the port is open:
```
sudo ufw status
```
If the command returns an error message or indicates that the port is closed, you may need to add a firewall rule to allow incoming connections on the MySQL port:
```
sudo ufw allow 3306/tcp
```
Restart the MySQL service after adding the firewall rule.
4. Verify that you are using the correct username and password: Check that you are using the correct username and password to connect to the MySQL server. You can do this by logging in to the MySQL server using the command line client:
```
mysql -u username -p
```
Replace "username" with your MySQL username and enter your password when prompted. If you are unable to log in, you may need to reset your MySQL password or create a new user account.
阅读全文