I assume Docker already installed and running.
Pull mysql container
You can specify version (5.7). If version is not given it will download latest version.
C:\>docker pull mysql/mysql-server:5.7
5.7: Pulling from mysql/mysql-server
e64f6e679e1a: Already exists
478c78606b7e: Pull complete
81ab104e859d: Pull complete
d3565df0a804: Pull complete
Digest: sha256:79d65bf4360056b0709b4a1c4996f7ef8265ae6ca67462a8570ac1fa0855758b
Status: Downloaded newer image for mysql/mysql-server:5.7
Check docker image
C:\>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql/mysql-server 5.7 76ac6291d3cf 2 weeks ago 234MB
Run mysql instance
docker run --name mysql1 -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_DATABASE=homedb -p 3306:3306 -d mysql/mysql-server:5.7
Check docker processes
C:\>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
44f6c176bb23 mysql/mysql-server:5.7 "/entrypoint.sh mysq…" 14 seconds ago Up 13 seconds (health: starting) 3306/tcp, 33060/tcp mysql1
Connect MySQL on docker
docker exec -it mysql1 mysql -uroot -p
If you did not provide a password in docker run command then system will generate a password.
To change password and give some permissions:
C:\>docker logs mysql1 2>&1 | FindStr GENERATED
[Entrypoint] GENERATED ROOT PASSWORD: yBiG5ynmyvVurAw93HDok3buGhi
docker exec -it mysql1 mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
SHOW GRANTS FOR 'root'@'%';
Connect MySQL on client
C:\Program Files\MySQL\MySQL Workbench 8.0 CE>mysql -h localhost -P 3306 -u root -p
mysql> select @@hostname;
+--------------+
| @@hostname |
+--------------+
| 44f6c176bb23 |
+--------------+
1 row in set (0.00 sec)
0 comments:
Post a Comment