The error message **"Error: Can't connect to MySQL server on 'localhost' (10061)"** means that the client cannot connect to the MySQL server. The usual reasons are as follows:
1. **MySQL service is not started**
- The MySQL server may not be started. In Windows, you can open the Services manager, find the `MySQL` service and start it manually. In Linux, you can check if MySQL is running using the following command:
```bash
sudo systemctl status mysql # Ubuntu/Debian
sudo systemctl status mysqld # CentOS/Fedora
```
2. **Incorrect port number**
- By default, MySQL server uses port **3306**. If the port number in the configuration file has been changed, the client may not be able to connect.
- You can check the port number setting in the MySQL configuration file (such as `my.cnf` or `my.ini`) to ensure that the client is connecting to the correct port.
3. **Firewall blocks connection**
- The local firewall may be blocking the MySQL port. If the firewall has a rule enabled to block port 3306, you can temporarily disable the firewall or open the port. You can open port 3306 on Linux through the following command:
```bash
sudo ufw allow 3306 # Ubuntu firewall example
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent # CentOS/Fedora
sudo firewall-cmd --reload # Reload the firewall
```
4. **Binding address configuration problem**
- In the MySQL configuration file, the `bind-address` setting may only allow remote connections or only bind to a specific IP address. Make sure `bind-address` in the configuration file is set to `127.0.0.1` or `localhost` to allow local connections.
5. **Socket file is missing or the path is incorrect**
- On some systems, MySQL uses Unix Socket files for connections. Make sure the `socket` path in the configuration file is correct and that the file actually exists. By default, this file is usually located at `/var/run/mysqld/mysqld.sock` or a similar path.
6. **User permissions issues**
- It may also be impossible to connect if the connecting user does not have the appropriate permissions. Make sure the permissions on user `localhost` are correct, you can try to re-grant permissions using the following command:
```sql
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
```
Summary of solution ideas
Check the MySQL service status, port settings, firewall rules, binding address, Socket file and user permissions in order to ensure that the MySQL configuration and server settings are correct.