Error establishing a database connection on wordpress
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?
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
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.
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?
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.
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
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
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
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.
There are many reason for the issue if you get the error only sometimes
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.
If you got the error on both backend and frontend, check your database credentials are correct.
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.
精彩评论