WordPress: Error establishing a database connection

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

As PHP will only be supported on App Service on Linux after November 28, 2022. We will only discuss wordpress on Linux App service in this blog.

 

Sometimes, we may encounter the following error when accessing wordpress website.

 

Tony_Ju_5-1665294945671.png

 

It is very easy to understand that there is something wrong with the connection between the website and database. But how can we find more detailed information regarding this error?

 

We can enable WordPress debugging mode to check the detailed error message. The steps are as below.

 

1.Login to the newui of the scm site.(https://{sitename}.scm.azurewebsites.net/newui)

2.Click File Manager and find the wp-config.php file under site/wwwroot folder.

 

Tony_Ju_6-1665294987569.png

  

3.Change "define( 'WP_DEBUG', false);" to "define( 'WP_DEBUG', true );" in wp-config.php file. We can edit it directly from the newui portal.

 

With this change, you can try to access the wordpress site again without restarting the app service. You will see the detailed error message when accessing the website.

Tony_Ju_1-1665390397461.png

 

You may see below possible error messages. I added some suggestions for each kind of error for your reference.

 

Error 1: mysqli_real_connect(): (HY000/1045): Access denied for user 'gyomnlmsxk1'@'10.0.0.254' (using password: YES) in /home/site/wwwroot/wp-includes/wp-db.php on line 1753

         Access denied for user 'gyomnlmsxk1'@'10.0.0.254' (using password: YES)

Suggestion: Check if the credential is correct.

 

Error 2: mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve in /home/site/wwwroot/wp-includes/wp-db.php on line 1753

Suggestion: Check if the server url is correct. If the server url is correct, check if there is any network limitation between website and database.

 

Error 3: Unknown database 'tonywordpr_83b28fe8295b4846ef6d475eecee129_database'

Suggestion: Check if the database name is correct.

 

Leave a 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.