Last updated February 18, 2015. Created on October 12, 2013.
Edited by phdhiren, chiddicks. Log in to edit this page.

If you're seeing PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server, it's because Drupal can't connect to the database server specified in your settings.php. There are two likely reasons for this:

  1. Your MySQL database server is not responding because it has crashed or been stopped. If you have shell access to your server and command-line knowledge, check to see if the MySQL process is running and accepting connections. It may need to be restarted. Check with your hosting company or system administrator to investigate. This can happen at any time, even if you haven't made any configuration changes.
    • In many of the case, if no change done at server configuration or code level, there is possibility that Disk space of MySQL data partition is exhausted and almost fully utilized. To check quickly with df command
  2. The connection information you specified in settings.php is incorrect. Pay particular attention to the 'host' parameter as it instructs Drupal where to reach the database server. This is most likely to happen when you have moved the site to a new server or changed the server or database configuration.

Looking for support? Visit the forums, or join #drupal-support in IRC.


Siridivi’s picture

This one was very frustrating. Fixed this one on the command line. Using RHEL 6.

Check if SELinux is running. Run the following command (Linux newbies, ignore the starting # it's just there to indicate a command prompt).

# getenforce

If the result is "Enforcing", then turn off SELinux temporarily by running the next command. If it's not SELinux is not the issue.

# echo 0 > /selinux/enforce

Try your site again. If it comes up correctly then SELinux is blocking the site. We really do want a secure server, so turn enforcing back on.

# echo 1 > /selinux/enforce

I have found two pieces to this puzzle: mysql and httpd.

The following command opens up the standard 3306 for MySQL communications (probably already set).

# semanage port -a -t mysqld_port_t -p tcp 3306

The following commands opens up communication between Apache and MySQL (don't get me started!). Thanks goes to

# setsebool httpd_can_network_connect_db 1

This change is not persistent across reboots. To make changes persistent across reboots run the following command.

# setsebool -P httpd_can_network_connect_db on

Those were the steps I needed to take. If your server isn't hosted locally (on the same server as your web server), you may also need to allow remote connections to MySQL. Here are some resources for that.