-
Go to docker official site, download docker file and install in the local machine.
-
Start docker, type in the following command to ensure docker is running.
docker images
-
Download MySQL image form docker hub with following commands.
docker pull mysql/mysql-server
docker pull mysql/mysql-server:5.7
(version 5.7) -
Start MySQL server in the container, forward the port out for host connection.
docker run --name mysqld -e MYSQL_ROOT_PASSWORD=1234 -d -p 3306:3306 mysql/mysql-server
or
docker run --name mysql57 -e MYSQL_ROOT_PASSWORD=1234 -d -p 3306:3306 mysql/mysql-server:5.7
-e: Set environment variables
-
Host connects to MySQL server in docker.
docker exec -it mysqld bash
bash> mysql -u root -p
(ask for password)Using sequel pro , a free GUI to manipulate MySQL server. MySQL Workbench is another good choice!
-
Stop the container.
docker stop mysqld
-
Start the container.
docker start mysqld
-
List port mappings or a specific mapping for the container
docker port mysqld
-
Remove container.
docker rm mysqld
-
Local host client can not connect to the MySQL server since ‘root’ is limited to localhost connection (within the container).
mysql> select host, user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | healthchecker |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)
Change root’s access right for all machines.
mysql> update mysql.user set host='%' where user='root';
mysql> select host, user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | healthchecker |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
4 rows in set (0.00 sec)
Restart docker afterward.
docker restart mysql57
No comments:
Post a Comment