Error creating database connection in wordpress

I have a wordpress blog, but sometimes I have a problem with this

I got an error with an error

Error creating database connection. This means that the username and password information in your wp-config.php is incorrect or we cannot contact the database server in %s . This may mean that your host database server is down.

Do you have the correct username and password? Are you sure you typed the correct hostname? Are you sure the database server is running? If you do not know 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 configuration 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 did I get this error sometimes , what do you think of this problem?

i contact my admins server and they said: "We have no problems with the server and mysql service"

Does my server have a problem or my configuration has a problem?

+6
php mysql web-config wordpress
source share
8 answers

Why did I get this error sometimes , what do you think of this problem?

This is the key; if this happens sometimes, this is an intermittent problem on the web host. The web host needs to look in MySQL logs and PHP logs for connection errors, timeouts, MySQL failures, etc., Something that will indicate the cause of intermittent problems.

If you have a "Error connecting to the database" all the time, this indicates a specific error that you made in wp-config.php .

Tell the web host and administrator to look at their logs to see when the MySQL server crashes and why.

If this is your own server, you need to know the OS and other data so that you can search overflow for information. Depending on the OS, the places of registration vary.

+1
source share

If you get it 'sometimes' , then PHP Scrpt was unable to connect to the database. One reason for this may be a database server for a while.

+1
source share

Try changing your DB_HOST to localhost

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

In addition, did you configure the database and fill in the username, password and database in your configuration?

0
source share

If you are not using the default port 3306 for MySql, give the host name with the 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. 

It will work

0
source share

The first thing you need to do is make sure that you get the same error both on the website interface and on the internal website interface (wp-admin). If the error message is the same on both pages, β€œError connecting to database”, continue to the next step. If you have another error in wp-admin, for example, "One or more database tables are not available. You may need to restore the database," then you need to restore your database. You can do this by adding the following line to the wp-config.php file:

define ('WP_ALLOW_REPAIR', true);

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

Remember that the user does not have to be logged in to access this function when this definition is installed. This is due to the fact that its main goal is to restore a damaged database; users often cannot log in when the database is damaged. Therefore, as soon as you finish restoring and optimizing your database, be sure to remove it from your wp-config.php.

Regard LatestTutorial.com

0
source share

get the correct database host name from the database

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

0
source share

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

0
source share

For some time this happens, only due to incorrect credentials, so check your credentials or try resetting your username and password, some temporary problem with the host or you can restore the database, just go to your wp-config file and write define ('WP_ALLOW_REPAIR', true); and repair it and do not forget to delete this line after repair.

0
source share

All Articles