DEV Community

Madhav Jha
Madhav Jha

Posted on

2 2

Docker MySQL setup on Mac OS X

Kill all running docker containers

docker ps -aq | xargs -r docker stop; docker ps -aq | xargs -r docker rm
Enter fullscreen mode Exit fullscreen mode

Start a MySQL server

Very Important is the flag MYSQL_ROOT_HOST is set to %.

docker run -d --name=local-mysql -p 54321:3306 -e MYSQL_ROOT_HOST=% -e MYSQL_ROOT_PASSWORD=password mysql/mysql-server
Enter fullscreen mode Exit fullscreen mode

Connect to MySQL using mac's mysql

export PATH="$PATH:/usr/local/mysql/bin"
# restart shell if required
mysql -h 127.0.0.1 -P 54321 -u root -ppassword
Enter fullscreen mode Exit fullscreen mode

Docker Compose Setup

version: '3'

services:
  db:
    image: mysql:5.7
    container_name: db
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_ROOT_HOST: '%'
    ports:
      - "54321:3306"
    volumes:
      - dbdata:/var/lib/mysql
volumes:
  dbdata:

Enter fullscreen mode Exit fullscreen mode

Save the above file as docker-compose.yaml. Then run the following commands to start/stop the container. The container will persist data across restarts. If you want to clean up the volume use docker-compose down -v command.

docker-compose up
docker-compose up -d # runs in the background
docker-compose down
docker-compose down -v
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay