Skip to content

Effortless MySQL Installation with Docker Compose!

How to install MySQL with docker and connect to Universal Database Tool (dBeaver) ?

for using docker, you need to install docker desktop in your local computer See installation. Next successfully install docker, please create file docker compose with name docker-compose.yaml Docker compose file

update it with following content:

version: '3.9'
services:
  mysql:
    image: mysql:5.7                    # name of image. if change version, please change here mysql:version (https://hub.docker.com/_/mysql)
    container_name: MySQLv5.7           # name of container
    restart: always                     # always restart
    environment:
      MYSQL_DATABASE: 'my_db'           # name of database
      # MYSQL_USER: 'sample'            # sample is the name of user
      # MYSQL_PASSWORD: 'mysql'         # password for sample user
      MYSQL_ROOT_PASSWORD: 'root'       # password for root user
    ports:
      - '3306:3306'                     # host port 3306 is mapper to docker port 3306
    expose:
      - '3306' # expose port 3306, so we can connect to the database from outside the container
    # command:
    #   --sql_mode=  # disable sql_mode

    volumes:
      - mysql-db:/var/lib/mysql # mount a volume for the database data

volumes:
  mysql-db:

next steep running docker compose, please use following command:

    docker-compose up -d

check your docker container status in docker desktop: Check Docker container status

Connect to Database Tool

This project is using Universal Database Tool (dBeaver community) to connect to MySQL. Please install dBeaver in your local computer See installation. Open dBeaver and click on New Databases Connection tab, and top up form database connection select MySQL and click next button. Select MySQL

enter connection details and click test connection button. connection detail

if test connection success, you can connect to database tool. test connection

click on OK button and click on Finish button, you can connect to database tool. Right click the connection that has been created, then click on connect and the database tool will connect

connect your db connected your db

Good luck and have fun. Enjoy your code.