MySQL Connection Errors and Troubleshooting

This article will assist you to fix the common causes of MySQL connection errors along with steps to resolve them. 

Check If MySQL Server is Running


When you receive MySQL connection errors the first thing you should check is if MySQL server is running or not. MySQL server needs to be started before it accepts the connections from clients. On Windows machines MySQL service can be started from the services control panel (Start >> Run >> type services.msc + enter). On Linux machines MySQL server can be started either through cPanel/WHM or from Linux terminal. You can also check our knowledgebase article on How to start MySQL service in Windows and Linux machines.

Check if MySQL server is listening on the default port


By default MySQL server listens on port 3306 however, it can be changed for each MySQL instance. If you have configured MySQL server to listen to some other port, the same port must be specified while clients connect to MySQL server. To find the port on which MySQL is listening to, check out your mysql configuration file (my.ini or my.cnf).

Check if skip-networking configuration option is enabled in my.ini or my.cnf


Make sure that your MySQL server is not configured to ignore network connections. If the skip-networking option is not commented out in the MySQL configuration file, clients would not be able to connect to MySQL instance via TCP/IP. To turn off the skip-networking option, edit the MySQL configuration file (my.ini or my.cnf), locate the line containing the text skip-networking and comment it out appending with #.

Database username does not have privileges to connect


MySQL database users must have appropriate connection privileges to be able to connect to MySQL instance. These privileges can be specified while you create a database username or else you can edit an existing username and specify necessary permissions. You can directly set permissions from web based MySQL server manager like phpMyAdmin or through Linux terminal. For example, following MySQL statements will give the user dbuser all privileges, including connection privileges (for localhost only).

GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'localhost';

Following command can be used to give user the dbuser all privileges including the permission to connect remotely.

GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'localhost' IDENTIFIED BY 'your-password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%' IDENTIFIED BY 'your-password' WITH GRANT OPTION;


bind_address configuration option is set to 127.0.0.1 in my.ini or my.cnf


If the bind_address configuration is set to 127.0.0.1 in the MySQL configuration file, MySQL server won't accept connections from remote hosts. To allow remote connections, you can remove or comment out the line bind_address line in the MySQL configuration file.

 
Check if firewall is blocking incoming connections to MySQL server


The firewall where the MySQL server resides must be configured to allow transmission via the port on which MySQL is listening. If the MySQL port is blocked in server firewall, the client will not be able to connect. Check out the following articles to open ports in Windows and cPanel/WHM machines.


  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

Fix :: Unable to login at phpMyadmin after revoking MySQL root user

Problem Statement I am not able to login into phpMyadmin after revoking root user. Solution...

How to Repair a MySQL Database Through Linux and Windows Command Line?

This article describes how to repair MySQL database tables through Linux and Windows command...

Fix - PHPMyAdmin Error You should upgrade to MySQL 5.5.0 or later

Problem statement Recently we upgraded phpMyAdmin version from 4.0.10.12 to 4.5.3.1 in our...

How to Fix MySQL Error "The server quit without updating PID file"?

MySQL server plays a vital role for your Linux Server. It runs all of your website's databases,...

How to Backup and Restore MySQL Databases From Command Line?

mysqldump is an easy and quick tool to create backup of MySQL databases. It creates a dump file...