Aim
Want to:
- Run MySql through docker
- Remote connect to MySql server
- From host to docker container
Reference
Steps
- Install and create new user so that we can do a remote connection
$ sudo docker pull mysql/mysql-server:latest
$ docker run -p 3306:3306 --name=mysql1 -d mysql/mysql-server:latest
# Get the auto generated password
$ docker logs mysql1 2>&1 | grep GENERATED
GENERATED ROOT PASSWORD: Axegh3kAJyDLaRuBemecis&EShOs
# Going into the docker container
$ docker exec -it mysql1 mysql -uroot -p
#
#
Server version: 8.0.17
#
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#
# You needed to reset your password
mysql> SET PASSWORD = '12345678';
# Create a new user and let remote access possible
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
- Connect from host to docker container
$ mysql -h localhost -P 3306 --protocol=tcp -u sec_user -p
沒有留言:
發佈留言