Setup Local MariaDB Server on Docker - gecko-8/devwiki GitHub Wiki

Up

Setup

  1. Download and install Docker for Mac
  2. Pull down the latest image for MariaDB (optional, will be pulled by next command if you don’t have it)
    sudo docker pull mariadb
    
  3. Create and run the container
    docker run --name mariadb-server -v /Data/Databases/MariaDB:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=<password> -p 3306:3306 -d mariadb:latest
    
    Note: This stores your data files in the folder /Data/Databases/MariaDB. This can be changed to any location you want.

Connecting

  1. To connect an external program, just use localhost, port of 3306, user of root, and password of .

Deleting

  1. Stop the container
    docker stop mariadb-server
    
  2. Delete the container
    docker rm mariadb-server
    
  3. Delete the data folder if you want. E.g. /Data/Databases/MariaDB
  4. Delete unused images (optional)
    docker image prune -a -f
    

Initializing a DB From a Large SQL Script

  1. Copy the script into the local data location from above (e.g. /Data/Databases/MariaDB)
  2. Connect to bash in your container:
    docker exec -it mariadb-server bash
    
  3. Connect to mysql as root with the command:
    mysql --user=root --password
    
  4. Set the default database:
    use <database name>
    
  5. Execute the script:
    source var/lib/mysql/<script name>.sql
    
⚠️ **GitHub.com Fallback** ⚠️