Install MySQL 8 using Docker easily

In my previous article we discussed about installing MySQL 8 using Docker in several steps. Now lets see how it can be done in one step.

$ docker run --name mysql_singlestep  -v mysqldbvol:/var/lib/mysql   -p 3307:3306 -e MYSQL_USER=usr_mysql -e MYSQL_PASSWORD=mypwd -e MYSQL_DATABASE=sample -e MYSQL_ROOT_PASSWORD=supersecret -d mysql/mysql-server:latest

Lets see what this command does

–name mysql_singlestep : Is the name of the container which can be changed based on your need.

-v mysqldbvol : is name of the volume.

-e MYSQL_USER=usr_mysql : creates an user “usr_mysql”

-e MYSQL_PASSWORD=mypwd : sets password for user “usr_mysql”

-e MYSQL_DATABASE=sample : creates a default database called “sample”

-e MYSQL_ROOT_PASSWORD=supersecret : sets password for user “root”

Using this command docker container can be verified.

$ docker ps

By default root can be connected only from local docker instance and cannot be connected from host machine.

To log into Bash of mysql system

$ docker exec -it mysql_singstep bash

# mysql -h localhost -u root -p

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: