DEV Community

Z. QIU
Z. QIU

Posted on • Edited on

2 2

Installation of Mysql in Docker (Ubuntu 18.04)

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

3) Check if MySql container is working correctly:

docker ps -a | grep mysql
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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*#!');
Enter fullscreen mode Exit fullscreen mode

if everything goes Ok, it shall yields output like:

Query OK, 0 rows affected, 1 warning (0.00 sec)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

7) Re-launch our Mysql service in container:

sh ~/launchers/mysql_docker_22345.sh
Enter fullscreen mode Exit fullscreen mode

8) Re-check if Mysql container is working correctly

docker ps -a | grep mysql
Enter fullscreen mode Exit fullscreen mode

Now try connecting it from Heidi:

Alt Text

Enjoy!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →