Docker MySQL setup on Mac OS X
Madhav Jha
Posted on May 30, 2022
Kill all running docker containers
docker ps -aq | xargs -r docker stop; docker ps -aq | xargs -r docker rm
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
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
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:
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
đź’– đź’Ş đź™… đźš©
Madhav Jha
Posted on May 30, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024