WordPress unable to connect to MySQL from GCP Compute Engine VM
I have a Google Cloud Platform Compute Engine VM instance where I have Apache installed. I wanted to put WordPress on here and have the MySQL database created locally instead of using another GCP Resource API.
I've finished installing MySQL locally and created a database and user and granted access as well. But when I try installing WordPress I get this 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 atlocalhost
. This could mean your host’s database server is down.
I've read that I might need to add the mysql-server
tag to my VM instance and add a firewall rule to allow TCP 3306 which I have now set up. But when I retry WordPress it still gives the same error. I also tried using my static external IP address when trying to connect WordPress to the database but no dice. I don't know how else to troubleshoot this.
Also, if it helps, I installed MySQL 8.
MySQL 8.x is actually ‘IS’ supported, but requires a slightly different command when creating the user and password, as version 8 expects passwords to be SHA256 encoded.
When creating the database user, with the MySQL prompt, use the following:
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
So WITH mysql_native_password being the main difference.
To troubleshoot the case you can also check out this link