This guide provides information on how to setup a local mysql database server using docker. Docker allows the use of mysql server from within a container. This is ideal for development and testing, without the lengthy process of a full install of mysql on your local machine. This guide will focus on the Ubuntu Linux operation system version 16.04.6 LTS.
> apt-get install docker.io
Download latest mysql docker container
> docker pull mysql:latest
Start new docker container (called mysql1)
> docker run --name mysql1 -e MYSQL_ROOT_PASSWORD=my-pw -d -p 3306:3306 mysql
Check mysql server container is up and running
> docker ps
Check the output logs of docker container
> docker logs mysql1 2>&1
Connect to new mysql server
> mysql -h 127.0.0.1 -P 3306 -u root -p
Note: if you do not currently have mysql client install, then use install
> apt-get install mysql-client
Note: if you receive error as below, wait few mins for mysql to setup, or monitor logs, as shown above. ERROR 2013 (HY000): Lost connection to MySQL server at ‘reading initial communication packet’, system error: 2
Or you can connect to your local mysql server using a light weight mysql GUI called emma
> apt-get install emma
To stop mysql docker container
> docker stop mysql1
To remove mysql docker container
> docker rm mysql1
Local MySQL DB Setup Create user with database.
> CREATE USER 'user'@'%' IDENTIFIED BY 'password'; > CREATE DATABASE dbname; > GRANT ALL PRIVILEGES ON dbname.* TO 'user'@'%'; > FLUSH PRIVILEGES;
Note @’%’ grants user can connect from any host, this should not be used in production.
This work was conducted as part of my research into music and its effect on mood study.