Using MySQL from a Docker Container in Mac

From Logic Wiki
Jump to: navigation, search

Pull docker image of MySql 8.0.20

docker pull mysql/mysql-server:8.0.20

List the images

docker images

Run the image for the first time

docker run --name=mysql1 -d mysql/mysql-server:8.0.20

Bette, run it with port mappings

docker run -p 3306:3306 -p 33060:33060 --name=mysql1 -d mysql/mysql-server:8.0.20        including port mapping

Get running containers

docker ps

Flush it to screen

docker logs mysql1

Get the random password

docker logs mysql1 2>&1 | grep GENERATED            to get root password

Run mysql to change the random password

docker exec -it mysql1 mysql -u root -p              

and enter the password you get with the line above

ALTER USER 'root'@'localhost' IDENTIFIED BY 'C1pralex'
\go
\q    

Set the permissions of root to accept connection from everywhere:

open bash

docker exec -it mysql1 bash 
mysql -u root -p
SELECT host, user FROM mysql.user;

It has to contain a line with your database user and '%' to works (% means "every IP addresses are allowed"). update mysql.user set host = '%' where user='root';

docker stop mysql1
docker start mysql1