Project

General

Profile

Docker Tips

Mysql

New Database

# Create folder for data /path/to/db
$ mkdir /path/to/db

# Create container
$ docker run -d --name CONTAINER -e MYSQL_ROOT_PASSWORD=XXXX -e MYSQL_DATABASE=DATABASE -e MYSQL_USER=USER -e MYSQL_PASSWORD=PASSWORD -v /path/to/db:/var/lib/mysql mysql:5.6

Backup Database

$ docker exec -i CONTAINER mysqldump -uroot -pXXXX DATABASE > backup.sql

Restore Database

$ cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -uroot -pXXXX DATABASE