A Glance At What Can Go Wrong Between Your WordPress Installation and MySQL

While installing your wordpress package, you might often have seen errors like “Error establishing a database connection”. There four possible causes to this error.

While installing your wordpress package, you might often have seen errors like “Error establishing a database connection“. What are the causes of this behaviour from wordpress?

Assumptions:

  • You have installed your wordpress package on a linux system (I’m sorry, I don’t use Windows and can’t less for it)
  • You are fairly familiar with wordpress and php
  • I’m using WordPress version 2.9.2 for this article

4 Possible Causes To Account For What Can Go Wrong Between Your WordPress Installation and MySQL

1) Your webserver is not able to synchronize with your MySQL server – cannot find MySQL Server

WordPress error throwned on page: “Error establishing a database connection

The typical nature of this issue is more often associated with cause 4) below.
But on rare occasions, this is the result of your web server not being able to find a MySQL socket file, named as mysql.sock
This socket file is a local MySQL instance generated by the program mysqld to allow a webserver to establish a connection with the MySQL server. You have to know where this mysql.sock resides on your machine.
If you have installed MySQL as an independent package, this will most probably be located in this path: /var/mysql/mysql.sock
If you have installed a XAMPP package, your mysql.sock will no doubt be found here: [your_root_path]/lampp/var/mysql/mysql.sock

Next, you need to be aware that WordPress will by default (via the PHP engine’s MySQL module) look for the mysql.sock in the path: /tmp/mysql.sock
In case you have this issue of mysql.sock , you can attempt to fix it by symbolically linking one
to the other as follows:

$ ln -s /tmp/mysql.sock /var/mysql/mysql.sock
OR
$ ln -s /tmp/mysql.sock /lampp/var/mysql/mysql.sock

Now what the heck is this mysqld ? Here’s an explanation from the MySQL Reference manual:

mysqld, also known as MySQL Server, is the main program that does most of the work in a MySQL installation. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.

When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.

2) Wrong login/password combination provided to access your WP database.

Associated settings in your wp-config.php are DB_USER and DB_PASSWORD respectively.

WordPress error throwned on page: “Error establishing a database connection”

3) Your login/password combination is good, authentication with the MySQL server is OK, but cannot find the name of the database you provided.

Associated settings in your wp-config.php is DB_NAME

WordPress error throwned on page: “Error establishing a database connection”

4) Your web server cannot find the designated database host, typically defaulted to localhost on most servers.
You have to note here that this error will usually give rise to error 1) above. So you might consider this one as being a possible action for the reaction in 1).

Associated settings in your wp-config.php is DB_HOST
Wordpress error throwned on page: “Error establishing a database connection”

Side thought: On local devs, you surely do not want to get those same errors each time. So, check out a possible solution to those boring same errors.

How about your observations? Do have any suggestions?

PS: If you are having headaches with your wordpress installation, you can hire my services to do your wordpress installation and updates!


2 Comment(s)

  1. I was learning to modified wordpress on my pc with xamp.
    But I fail…

    I’ll try your guidance. Thanks…

  2. I discovered your weblog web page on google and check a number of of your early posts. Continue to help keep up the extremely very good operate. I just extra up your RSS feed to my MSN News Reader. Looking for forward to reading far more from you later on!?-



Leave a Reply to Ali Ale Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.