Error establishing a database connection on wordpress
Asked Answered
R

10

12

i have a blog with wordpress but sometimes i have problem with that

i got blow error

Error establishing a database connection 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 %s. This could mean your host's database server is down.

Are you sure you have the correct username and password? Are you sure that you have typed the correct hostname? Are you sure that the database server is running? If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums

and this is my config file

define('WP_HOME','http://www.mysite.com');
define('WP_SITEURL','http://www.mysite.come');
define('DB_NAME', 'mydbname');

/** MySQL database username */
define('DB_USER', 'dbusername');

/** MySQL database password */
define('DB_PASSWORD', 'dbpassword');

/** MySQL hostname */
define('DB_HOST', 'mysite.com');

why i got this error sometimes what do you think about this problem?

i contact with my admins server and they said "we dont have any problem with server and mysql service"

does my server have problem or my config have problem?

Rame answered 29/11, 2010 at 10:16 Comment(0)
P
2

why i got this error sometimes what do you think about this problem?

That's the key; if it only happens sometimes, it's an intermittent issue at the webhost. The webhost needs to look in the MySQL logs and PHP logs for connection errors, timeouts, MySQL crashes, etc, anything that will point to the cause of the intermittent issues.

If you had "Error establishing a database connection" all the time, that points to a definite error you made in wp-config.php.

Tell the webhost and administrator to look at their logs to see when the MySQL server is going down and why.

If this is your own server, you need to know the OS and other details so you can search Stack Overflow for the information. Log locations vary, depending on the OS.

Peggi answered 29/11, 2010 at 18:34 Comment(1)
Ok in Ubuntu /var/log/mysql is the answer. But these files are emptySvelte
D
7

If your are not using default port 3306 for MySql, do give the host name with port number.

define('WP_HOME','http://www.mysite.com');
define('WP_SITEURL','http://www.mysite.come');
define('DB_NAME', 'mydbname');

/** MySQL database username */
define('DB_USER', 'dbusername');

/** MySQL database password */
define('DB_PASSWORD', 'dbpassword');

/** MySQL hostname */
define('DB_HOST', 'localhost:3307'); //If you are not using default port number, do give post number along with localhost.

This would work

Demolition answered 24/12, 2012 at 7:4 Comment(0)
P
2

why i got this error sometimes what do you think about this problem?

That's the key; if it only happens sometimes, it's an intermittent issue at the webhost. The webhost needs to look in the MySQL logs and PHP logs for connection errors, timeouts, MySQL crashes, etc, anything that will point to the cause of the intermittent issues.

If you had "Error establishing a database connection" all the time, that points to a definite error you made in wp-config.php.

Tell the webhost and administrator to look at their logs to see when the MySQL server is going down and why.

If this is your own server, you need to know the OS and other details so you can search Stack Overflow for the information. Log locations vary, depending on the OS.

Peggi answered 29/11, 2010 at 18:34 Comment(1)
Ok in Ubuntu /var/log/mysql is the answer. But these files are emptySvelte
R
2

If you get it 'sometimes' then it means the PHP Scrpt wasn't able to connect to the database. One of the various reasons could be database server down for a while.

Rodrigues answered 30/11, 2010 at 12:39 Comment(0)
B
1

first type mysql -u root -p and enter the your mysql password then type GRANT ALL PRIVILEGES ON mydbname.* TO dbusername@localhost; then FLUSH PRIVILEGES; and finally exit

Bathelda answered 4/11, 2016 at 7:37 Comment(0)
G
1

i just newly installed wordpress on my xampp it shows me same error! i solved it by passing database name correctly, and for username should be root, and by let the pssword field empty and then preceed next helps to fix my issue!

Gardell answered 27/9, 2023 at 5:58 Comment(0)
N
0

Try changing your DB_HOST to localhost

** MySQL hostname */
define('DB_HOST', 'localhost');

Furthermore, have you set up the database and filled in the username, password & database in your config?

Nathalie answered 29/11, 2010 at 10:18 Comment(0)
P
0

First thing you should do is to make sure that you are getting the same error on both the front-end of the site, and the back-end of the site (wp-admin). If the error message is the same on both pages “Error establishing a database connection”, then proceed onto the next step. If you are getting a different error on the wp-admin for instance something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database. You can do this by adding the following line in your wp-config.php file:

define('WP_ALLOW_REPAIR', true);

http://cdn4.wpbeginner.com/wp2-9/dbrepair.gif

Remember, the user does not need to be logged in to access this functionality when this define is set. This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.

Regard LatestTutorial.com

Procryptic answered 11/11, 2013 at 9:22 Comment(0)
A
0

get the correct DB host name from the database

use following quesry for mysql select @@hostname; change the value of the DB_HOST to output of above query

Ambrosius answered 13/2, 2016 at 19:37 Comment(0)
D
0

Some time this happen , just because of incorrect credentials so check your credentials or try to reset your user name and passward , some time host issue or you can repair the database just go to your wp-config file and write define ( 'WP_ALLOW_REPAIR' , true); and repair it and don't forget to remove this line after repair.

Degradation answered 7/7, 2017 at 11:27 Comment(0)
M
0

There are many reason for the issue if you get the error only sometimes

  1. If your database is very big, it can not handle the queries. ( You probably see 'too many database connections' or 'user already has more than 'max_user_connections' active connections' errors on error logs. So try to reduce database tables size.

  2. If you got the error on both backend and frontend, check your database credentials are correct.

  3. If the error only on the front end. try to repair database by adding the following line of code in wp-config.php

define('WP_ALLOW_REPAIR', true);

Then go to 'http://www.yoursite.com/wp-admin/maint/repair.php' and click 'repair and optimize database' button.

Myriam answered 2/5, 2018 at 5:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.