- Check MySQL Server Status: First, ensure that the MySQL server is running. You can do this by executing the command:
sudo systemctl status mysql
If the server is not running, start it with:
sudo systemctl start mysql
- Verify Network Connectivity: Check if the MySQL server is reachable over the network using the `ping` command followed by the server's IP address or hostname.
ping [MySQL
Server
IP/Hostname]
- Check Firewall Settings: Ensure the firewall is not blocking the connection to MySQL. You can check if the MySQL port (default is 3306) is open by using:
sudo ufw status
If it's blocked, allow it with:
sudo ufw allow 3306
- Inspect MySQL User Permissions: Verify that the user has the correct permissions and is allowed to connect from the host. Log into MySQL from a terminal or command prompt that has access and run:
SHOW GRANTS FOR 'your
username'@'your
host';
Replace `'yourusername'@'yourhost'` with the actual username and host you're connecting from.
- Review the MySQL Error Log: Check the MySQL error log for any specific messages related to the connection issue. The location of the log file can vary, but you can find it by checking the MySQL configuration file or running:
sudo grep 'log_error' /etc/mysql/my.cnf
Then view the log with:
tail -f /path/to/mysql/error.log
- Increase the max_connections Setting if Necessary: If the server is reaching its connection limit, increase it by editing the MySQL configuration file (`/etc/mysql/my.cnf` or `/etc/mysql/mysql.conf.d/mysqld.cnf`) and setting:
[mysqld]
max
connections = [new
limit]
Apply the change by restarting MySQL:
sudo systemctl restart mysql
- Check for IP Binding Issues: Ensure MySQL is not bound to a specific IP address. Check the `bind-address` directive in the MySQL configuration file (`/etc/mysql/my.cnf` or its included files). If it's set to an IP address other than the one you're connecting from or `0.0.0.0` (for listening on all interfaces), you may need to change it.
- Test MySQL Connection Locally: If you have access to the server, try connecting to MySQL locally using the command line to rule out network issues:
mysql -u [your_username] -p
These steps should help identify or resolve the "Error 1134: Connection failed" issue with your MySQL database.