Local Worpdress website can not connect to its database

294 Views Asked by At

I am trying to install a Wordpress site on a local server (Ubuntu 16.04 in a docker container).

Xampp is installed and running, and I have created a database and a username with proper rights:

mysql -uroot -e "CREATE USER 'localuser'@'localhost' IDENTIFIED BY 'localpassword';";
mysql -uroot -e 'CREATE DATABASE 'localdatabase';';
mysql -uroot -e "GRANT ALL ON localdatabase.* TO 'localuser'@'localhost';";

I've also updated my wp-config.php file with the credentials above.

Still, when I try to install wordpress from there (I use wp-cli), I get the message "Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down."

I've double checked the credentials, and xampp is indeed running, so what should I check next? Could this come from a config file that is missing something?

2

There are 2 best solutions below

6
On

What hostname are you using in the wp-config? Also did the commands finish succesfully? For creating the db you used apostrophes instead of quotes. You can try the mysql client directly with mysql -u -p -h .

0
On

In wp-config.php, use 127.0.0.1 instead of localhost for the database hostname.