# WordPress.org

## Error establishing a database connection (37 posts)

1. agmal
Member
Posted 9 years ago #

hello every 1
i always got this erorr msg

"This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at localhost.

Are you sure you have the ?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running? "

I'm sur that i have the correct username and password and typed the correct hostname and the datebase is running :D
so where is the proplem
i laso sometimes can't get step 2

I tryed to use word press in local host and it's worked well
but when i tryed it in my site i can't :S so are the proplem from the cpanel ?

2. astrashe
Member
Posted 9 years ago #

I just had the same problem on my home machine.

I doubt my problem was the same as yours -- it turned out that my version of PHP (4.x) didn't get along with my new version of MySQL. I upgraded to PHP5, and it worked.

I was able to diagnose my problem by writing a really simple PHP script that tried to connect to the database, and looking at the specific error.

(If the developers read this, I'd suggest including the specfic error message on the "can't connect" page. The argument against it is probably that it would just confuse people. But if you see that page, you're going to be confused anyway.)

Anyway, I used this to get a more specific error message -- replace the connection parameters with what you're using on your server, put this in a file called something.php, and pull it up in your browser.

<html> <head><title>test</title></head> <body>

 <?php \$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error()); ?> 

</body> </html>

3. DaveMH
Member
Posted 9 years ago #

Thank you - this helped me track down my problem - which was to enter at the mysql prompt

This seems to be a very common problem.

4. rbassman
Member
Posted 9 years ago #

I'm getting the same error message, attempting to access my site to run the installer script. I ran the php script above (thanks!), and this is what it reports.

Could not connect: Unknown MySQL server host 'mysql_host' (3).

I'm using TextDrive, is this something I need to contact them about, or have I not set my wp-config.php file properly?

5. rbassman
Member
Posted 9 years ago #

see post:

http://wordpress.org/support/topic.php?id=26796

I'm set up, and thanks for all the really rapid help, this forum rocks.

6. goodfish
Member
Posted 9 years ago #

Hello there,
This is my first post and I'm a complete newbie to this. I am having the same problem and was wondering if someone could expound on DaveMH's post above, about entering

at the "msql prompt". Is that within the wp-config.php file...or where? Thanks in advance for any help!

7. moshu
Member
Posted 9 years ago #

No, no. Don't put anything like that into config file!

8. goodfish
Member
Posted 9 years ago #

I won't. It's when I bring up the installation page in my browser, I get the error message that it can't connect to the database with localhost. I can log in to phpMyAdmin through my Network Solutions account, using the same username and password that I have in the config file. Thanks for your quick reply!

9. moshu
Member
Posted 9 years ago #

Those (username and pw) are not necessarily the same! For phpMyadmin usually you use the same as for your site administration. The username and pw for the database itself might be different. Was the database created by you or by your host? (I am not familiar with NS, my host offers CPanel to access my site admin.) If it was created by your host, they should provide you with the necessary info you have to put in the config file.

10. goodfish
Member
Posted 9 years ago #

I just created it today through thier "database manager". I did get on the phone with NS tech support, and I do have the right username and password. What I am wondering is about the part where it asks, "are you sure the database server is running". When I log into phpMyadmin, in the process list it has my ID, user and host, but under database it says "none". Could that mean something?

11. moshu
Member
Posted 9 years ago #

OK, then create a database named whatever you want, and if it's done, put its name in the config file.

12. goodfish
Member
Posted 9 years ago #

That is what I did, but I am hung up on step 5. I get the error message at the beginning of this thread when I go to http://www.mysite.com/wp-admin/install.php

13. moshu
Member
Posted 9 years ago #

In the phpMyadmin on left menubar in the dropdown menu can you see the name of the database you've created?

14. goodfish
Member
Posted 9 years ago #

Yes

15. moshu
Member
Posted 9 years ago #

SO, in your config.php file (which you renamed from config-sample!!!) you have something like this?

<?php // ** MySQL settings ** // define('DB_NAME', 'name_you-see_in_phpmyadmin'); // The name of the database define('DB_USER', 'your_usernam'); // Your MySQL username define('DB_PASSWORD', 'your_pw'); // ...and password define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value

If everything is correct, then you probably are in the remaining 1% :) Ask your host.

16. goodfish
Member
Posted 9 years ago #

Alas, I did and it is indeed 'localhost'. :) And the rest of the stuff is all correct. I have no clue what is up. I will cruise around support some more and see if I find anything. One thing is, when I created the database earlier, I made the name of the database and my mySQL user name the same. Would that throw something off? Pardon my ignorance on all this... I really appriciate your time and don't mean to get tedious!!!

17. moshu
Member
Posted 9 years ago #

The only other thing I can think of... is the user added to the database?
(I know how to do it in CPanel, but have no clue about other admin interfaces, sorry.)

18. goodfish
Member
Posted 9 years ago #

I will check that, thanks very much!

19. stucurry
Member
Posted 9 years ago #

I am having the same problem with network solutions and was wondering has any solution to this problem been found?

20. puravida76
Member
Posted 9 years ago #

I am stuck on the exact same problem.

I am using:
Host: Lunarpages / cpanel X
PHP version 4.3.10
MySQL version 4.0.22-standard

I'm almost positive my wp-config.php file is configured correctly.

21. puravida76
Member
Posted 9 years ago #

It finally worked for me and I think the problem was that my login and password were the same words, or perhaps that my database name was the same my login name.

Anyone having trouble with this step should try diversifying those.

22. stucurry
Member
Posted 9 years ago #

i finally got it! turns out (with me anyway) i'm one of the 1%!
it worked when i changed 'localhost' to the address of my mysql thingy i.e.

define('DB_HOST', 'localhost');

became

define('DB_HOST', '205.XXX.XXX.XX');

23. mAg
Member
Posted 9 years ago #

I'm running into this 'Error establishing a database connection' problem as well.

-Win2K
-MySQL 4.1.11
-php 4.3.10

The wp-config settings should be fine. I've set up wordpress on a few other systems (however this is the first Windows installation I've attempted)

Using MySQL Admin I can connect to the service as localhost.
Tried substituting 127.0.0.1 in place of localhost, as well as a couple other IP's bound to the system, and the actual machine name. None of these worked. I also tried adding enable-named-pipes to my.ini, and restarted mysql, but it wouldn't start after that.

I've also ensured that my username is able to connect from localhost, as well as remotely. Seems to work using mysql admin tools, but not in WordPress.

Any other things that I should look at?
tia

24. smokinpope
Member
Posted 9 years ago #

in your php.ini file try setting doc_root = "leave blank" and make sure my.ini (for mysql) is under your c:\windows dir

[mysqld]
basedir=C:/MySQL/

with the following placed inside

25. mAg
Member
Posted 9 years ago #

thanks for the reply...I did check the php.ini, and the mysql my.ini, and all looks good there.

I did come across a reference to the old_password() function in mysql, and I applied this function to the user that I am using for the wordpress database.

Now, instead of the connection error, I recieve a page full of errors similar to this:

Warning: Invalid argument supplied for foreach() in \path\to\wordpress\wp-includes\functions.php

WordPress database error: [Table 'my_database.wp_options' doesn't exist]
SELECT option_value FROM wp_options WHERE option_name = 'permalink_structure'

26. mAg
Member
Posted 9 years ago #

problem resolved after upgrading php and reinstalling mysql. Part of the problem was the mysql user accounts... had to create a username@localhost acct, not just username

27. jeepfun
Member
Posted 8 years ago #

As an FYI, if you are using a Network Solutions hosting account, you can not specify the MySQL database as localhost. You have to go to where you created the MySQL Database in the Hosting Control Panel and get the IP address on that page and use that.

Good Luck

28. thephoenix
Member
Posted 8 years ago #

I'm also using Network Solutions, everything is working, but from time to time (alot of time:-) I keep getting the "Error establishing a database connection". Do you experience those on Network Solutions? If not, how did you do the trick :-)

29. beaniecopter
Member
Posted 8 years ago #

I found this topic (#26705) while trying to resolve my problem, which was the inability to log in to the remote database server using MySQL Administrator to perform a backup of a WordPress database for a blog hosted on lunarpages.com. Here is what I did to solve the problem.

I am using MySQL for a WordPress blog hosted by lunarpages.com. I installed WordPress using Fantastico from the lunarpages.com CPanel. Regrettably, CPanel and Fantastico have defaults which caused problems.

CPanel/Fantastico prefixes the lunarpages.com username ("foo") to whatever username and database name the user specifies when creating the database. If no name is specified, the default is "wrdp1". Moreover, CPanel/Fantastico by default makes the user name the same as the database name. So if you specify "bar" as the WordPress database name and your lunarpages.com username is "foo", the WordPress user name will be "foo_wrdp1". Likewise, the database name will be "foo_wrdp1".

I am running a Linux system, namely, Debian "sarge". I installed the package "mysql-admin", which is the MySQL Administrator. After several unsuccessful attempts to connect to the database server at lunarpages.com, I found in this topic a suggestion to change the username to a value distinct from the database name. So, using "MySQL Account Maintenance" in CPanel, I added user "bar", which CPanel turned into "foo_bar". So, with username "foo_bar" and servername "mydomain.com" (omitting the "www."), I was able to connect to the MySQL server at lunarpages.com, using MySQL Administrator.

My primary goal was to backup the database "foo_wrdp1". However, I discovered that the only database which mysql-admin could see was an empty data base with the schema (that is, name) "test". The problem turned out to be that user "foo_bar" had not been added to the user list for the database. So, I went back into "MySQL Account Maintenance" in CPanel and add user "foo_bar" to the user list for database "foo_wrdp1". When I exited and then restarted mysql-admin, I found "foo_wrdp1" listed as a schema, and now I am able to inspect the tables of the schema and perform a backup.

30. haakwaar
Member
Posted 8 years ago #

For me (Mac OSX 10.4.3, MySQL 5.0.13) updating the PHP module from version 4.x to 5.0.4 solved the problem (tx astrashe!).

This topic has been closed to new replies.