Solution:
So basically I included
bind-address = 0.0.0.0
in /etc/mysql/my.cnf above. It seems that the docker container can’t connect to MySQL on localhost by design. This allows mysqld to connect to the docker container on any IP.
Then make sure that your MySQL root user can also connect from non-localhost IP’s…
Login to MySQL from the Linux cli … Check if root is available from ‘%’ (any IP)…
mysql> SELECT host, user, password FROM user WHERE host = '%';
+------------------+------+-------------------------------------------+
| host | user | password |
+------------------+------+-------------------------------------------+
| % | root | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
+------------------+------+-------------------------------------------+
If you don’t see above then run to allow all access …
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
Then restart MySQL ..
service mysql restart
Then check to see where the MySQL service is bound ..
dara@dara-HP-Stream-Laptop-11-y0XX:~$ sudo netstat -tupan | grep mysql
[sudo] password for dara:
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 916/mysqld
Or since MySQL is configured to run on localhost only by default. You could comment out the following in my.cnf
# bind-address = 127.0.0.1
Which takes care of the MySql connection error issue.
Then since I’m running a wp-env docker container to create a WordPress image. I run a
wp-env clean all
Which cleans the WordPress databases … then I do a
wp-env --update --debug start
To create a WordPress docker container with access to MySQL
If that doesn’t work, then try a
wp-env destroy && wp-env start
Warning: wp-env destroy is the last resort and deletes docker containers, volumes, and networks associated with the WordPress environment and removes local files.
However, I had no docker containers, volumes or networks i wanted to preserve. This worked for me.