How to Solve the error “Error while connecting to DB”?”

 One I was also as my schedule opening my WordPress CMS from localhost but it gave me error Error in establishing DB connection.This can be happen due to multiple use creation of databases of CMS system daily or altering of the database,non-mysql passwords.This can be solved easily.

Step 1:

Open terminal connect to your mysql database.If you haven’t installed LAMP please go through this.Installing LAMP

$ sudo mysql -u root -p

will prompt for mysql database password.Enter that password which you were entered during mysql database.If you forgot the password please refer this .Resetting the mysql root password.

Step 2:

Create a database for wordpress.

mysql> CREATE database wordpress;

Step 3:

Creating a new user for the databse.

mysql> CREATE USER “wordpressuser”@”localhost” IDENTIFIED BY “newpassword”;

Step 3:

Grant all privileges to created user database.

mysql>GRANT all privileges on wordpress .* TO “wordpressuser”@”localhost”  IDENTIFIED BY “newpassword”;

Step 4:

Once the new user has been created and privileges has been assigned to it, run the command FLUSH PRIVILEGES; to flush the old privileges and start using the new assigned ones.

mysql> FLUSH PRIVILEGES;

Step 5:

Exit the database.

mysql>quit

Step 6:

Now try installing wordpress again.localhost/path/to/wordpress.(wordopress directory path)

Thank You.

Leave a comment