PS: This is my first encounter with wordpress and before posting this question I’ve checked many related posts and none of the answers resolved my problem. So please spare me if anything silly.

I’m trying to setup WordPress on a Linux machine(Ubuntu 14.04) and I’m following this tutorial. Everything was fine until I started editing wp-config.php, I ran into “Error establishing a database connection” error.

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'wordpress');

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

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('WP_ALLOW_REPAIR', true);

I’m sure that the values for DB_NAME,DB_USER and DB_PASSWORD are correct and I’m unsure of the value for DB_HOST. I’ve tried many variations for DB_HOST like below

define('DB_HOST', 'localhost:3306');
define('DB_HOST', '');
define('DB_HOST', '');
define('DB_HOST', '');
define('DB_HOST', '');

but non of the above couldn’t resolved the issue. I’ve also checked Mysql and Apache logs, but nothing about the error. Some information from Mysql shell

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 6291
Server version: 5.5.55-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
4 rows in set (0.00 sec)

mysql> select User,Host from mysql.user;
| User             | Host                              |
| root             |                         |
| root             | ::1                               |
| debian-sys-maint | localhost                         |
| root             | localhost                         |
| wordpressuser    | localhost                         |
| root             | npvr-vivek-2016-10-17-4gb-nyc3-01 |
6 rows in set (0.00 sec)

I’ve also tried restarting the Mysql,but the error remains. Any help will be greatly appreciated.

Read more here: WordPress+Mysql+Apche: Error establishing a database connection


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: