In this article, we will install the MySQL on docker, and configure additional account for specific database access only.
Install the MySQL on docker
- Check if you have installed the docker, by executing:
1 | sudo docker --version |
If it show the docker version, which means you have installed, if not you could install docker via the installation guide
- Pull the mysql image:
1 | sudo docker pull mysql:latest |
- Run a MySQL container with the following command:
1 | sudo docker run -d --name mysql_container -e MYSQL_ROOT_PASSWORD={Your Root Account Password} -p 3306:3306 mysql:latest |
- Verify that the MySQL container is running
1 | sudo docker ps |
- If you need make it always running
1 | sudo docker update --restart=always mysql-container |
Basic commands
- Entering the MySQL Console
1 | sudo docker exec -it {Your Container ID} mysql -u root -p |
and then entering you root password to enter the console.
- Create a new user with limited access to the specified databases:
1 | CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password'; |
If you wanna this additional account could be access externally, then replace localhost
to %
Verify the user has been created successfully and has access to the specified databases:
1 | SHOW GRANTS FOR 'new_user'@'localhost'; |
Exit the MySQL command line interface:
1 | exit; |