WordPress Error establishing a database connection in Linux server

Solution:1

can you check your wp-config.php file? see if got correct info. should be something like this.

 

// ** MySQL settings – You can get this info from your web host ** //

/** The name of the database for WordPress */

define(‘DB_NAME’, ‘wp’);

 

/** MySQL database username */

define(‘DB_USER’, ‘root’);

 

/** MySQL database password */

define(‘DB_PASSWORD’, ”);

 

/** MySQL hostname */

define(‘DB_HOST’, ‘localhost’);

Solution:2

Try going to /var/log/php-fpm and checking error.log file . In my case, I ran:

 

/etc/init.d/mysqld

 

status with message : mysqld dead but subsys locked

 

Turned out that mysql was stopped! How that happened remains a mystery since I did not change anything. The solution was to simply run:

 

/etc/init.d/mysqld start