google cloud platform – 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 at localhost. 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.