Link Search Menu Expand Document

Install MySQL

Table of contents

  1. Install MySQL on MacOS
    1. Prerequisite
    2. Choose A Place on your Mac
    3. Create docker-compose.yml
    4. Generate your MySQL Container
    5. Additional Commands

Install MySQL on MacOS


  1. You’re using Mac

  2. You should have Docker installed (if not, please check this link to install, and get back)

Choose A Place on your Mac

Open your terminal and locate to any path you want. Create a new folder name it “mysql”

Create docker-compose.yml

Type or copy the following code into it. Please take care of the indents (If you encounter any issue of the syntax of YML, please use this Online YML Checker) to help you.

[Optional] change the password to yours.

version: '3.3'
    image: mysql:5.7
    platform: linux/amd64
    restart: always
      MYSQL_DATABASE: 'db'
      # So you don't have to use root, but you can if you like
      MYSQL_USER: 'nonrootuser'
      # You can use whatever password you like
      MYSQL_PASSWORD: 'NonRootPassword'
      # Password for root access
      MYSQL_ROOT_PASSWORD: 'YourRootPassword'
      # <Port exposed> : < MySQL Port running inside container>
      - '3306:3306'
      # Opens port 3306 on the container
      - '3306'
      # Where our data will be persisted
      - my-db:/var/lib/mysql
# Names our volume

Generate your MySQL Container

Open your terminal and switch to the path as same as your docker-compose.yml file. Type the following command.

docker-compose up

If everything goes well, you would see a similar outputs like me.

Additional Commands

You can press “Ctrl-C” to stop the container. And then you can use “docer-compose start” to start you container in the future.

dockcer-compose start

After you want to stop your container. Please use below command.

dockcer-compose stop