Setup Local MariaDB Server on Docker - gecko-8/devwiki GitHub Wiki
- Download and install Docker for Mac
- Pull down the latest image for MariaDB (optional, will be pulled by next command if you don’t have it)
sudo docker pull mariadb
- Create and run the container
Note: This stores your data files in the folder /Data/Databases/MariaDB. This can be changed to any location you want.
docker run --name mariadb-server -v /Data/Databases/MariaDB:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=<password> -p 3306:3306 -d mariadb:latest
- To connect an external program, just use localhost, port of 3306, user of root, and password of .
- Stop the container
docker stop mariadb-server
- Delete the container
docker rm mariadb-server
- Delete the data folder if you want. E.g. /Data/Databases/MariaDB
- Delete unused images (optional)
docker image prune -a -f
Initializing a DB From a Large SQL Script
- Copy the script into the local data location from above (e.g. /Data/Databases/MariaDB)
- Connect to bash in your container:
docker exec -it mariadb-server bash
- Connect to mysql as root with the command:
mysql --user=root --password
- Set the default database:
use <database name>
- Execute the script:
source var/lib/mysql/<script name>.sql