WordPress Database Error establishing a database connection

The Post Created(Updated) On 05/6/2022,Please note the timeliness of the article!

Error establishing a database connection

I recently did a site migration, and migrated back again because of a master-slave synchronization problem, but I didn’t know how to do another site’s database connection to Error when I solved the synchronization. error is shown in the figure (Error establishing a database connection)

determine whether the password is correct

  • Go to the website directory to check the database information of wp-config.php.

  • Test the password with the database login information

mysql -uUsername -p
  • If you can log in successfully, check if the relevant table permissions exist, if not, cut the root user to change the password.
# I'm on 5.7 here
update mysql.user set authentication_string=password('passwd') where user='Username' and Host = 'localhost';
# flush privileges
flush privileges;
  • If root can’t switch either, change the database configuration, mainly by adding the following to [mysqld] in the mysql configuration file.
#Bypass password authentication
skip-grant-tables
  • If that doesn’t work, try a database restart

Verify permissions

  • If you can cut through the table
use dbName;

  • If you can’t, switch the root user to give the relevant privileges
mysql -uroot -p
grant all privileges on `database_name`. * to 'user_name'@'hostname';

Repair the database

  • Add the following code to wp-config.php
define('WP_ALLOW_REPAIR', true);
  • Log in to repair https://yourdomain.com/wp-admin/maint/repair.php, and click on repair.

  • If the repair is not good, it depends on the database backup situation, I finally started debug mode (wp-config.php enabled, logged into the background to see the error to check the problem is not authorized to the right permissions) plus the database backup to restore. It’s important to back up your data, but I’ve stepped in a hole, full of tears.
define( 'WP_DEBUG', true );


👇 Share This 👇


Copyright

Unless otherwise noted, all work on this blog is licensed under a Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License. Reprinted with permission from -
https://blog.emperinter.info/2022/05/06/wordpress-database-error-establishing-a-database-connection


CouPon

alibaba cloud20 dollars
Vultr10 Dollars
Bandwagon HostMaybe some Coupon?
Domain | namesiloemperinter 1Dollars