Info: This post is one of the articles in context of this post: Huawei Cloud ECS server notes
Just now, I installed MySql on my cloud server using Docker.
1) Create launcher file and mapping folders:
cd ~/launchers
touch mysql_docker_22345.sh
cd ~/docker
mkdir mysql_22345
2) Launch Mysql container using cmd line with initial password for root user (this will take some time because docker needs to pull the image from its server):
docker run --name mysql_docker_22345 -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -v /home/jemaloQ/docker/mysql_22345/mysql_conf/:/etc/mysql/ -v /home/jemaloQ/docker/mysql_22345/data:/var/lib/mysql -d mysql:5.7
3) Check if MySql container is working correctly:
docker ps -a | grep mysql
4) If container is running, then we need to change the password config. We enter the inside of the container and login MySql as root:
docker exec -it mysql_docker_22345 mysql -u root -p
then type the initial password and type enter.
5) Once we enter successfully MySql console inside the container, we change the password:
set password for 'root'=password('jemaloQ*#!');
if everything goes Ok, it shall yields output like:
Query OK, 0 rows affected, 1 warning (0.00 sec)
6) Now we copy the following script into our launch file:
docker rm -f mysql_docker_22345
docker run -it -d \
--name mysql_docker_22345 \
-p 22345:3306 \
-v /home/jemaloQ/docker/mysql_22345/mysql_conf/:/etc/mysql/ \
-v /home/jemaloQ/docker/mysql_22345/data:/var/lib/mysql \
mysql:5.7
7) Re-launch our Mysql service in container:
sh ~/launchers/mysql_docker_22345.sh
8) Re-check if Mysql container is working correctly
docker ps -a | grep mysql
Now try connecting it from Heidi:
Enjoy!
Top comments (0)