Using MySQL 8 on Docker for development

  • 08 Aug, 2019

These are my steps to create a MySQL Docker container, i am using Docker for Mac.

1 - Create a folder to save the database. If you do not create a Docker volume you will loose your data when you restart your container.  My folder is /Users/keniocarvalho/VolumesDocker/mysqdata

2- Execute the command bellow:

docker run –name mysqldb -p 3306:3306 -v /Users/keniocarvalho/VolumesDocker/mysqdata/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=yourpassword -d mysql/mysql-server:latest

3 - Enter on the mysql container using the command :  docker exec -it mysqldb bash

4 - Inside the container type : mysql -uroot -p. The system will ask for the password. Here the password is yourpassword.

5 - To access the database from outside the container run this commands on the mysql console:

CREATE USER ‘root’@‘%’ IDENTIFIED BY ‘root’;

GRANT ALL PRIVILEGES ON *.* TO ‘root’@‘%’ WITH GRANT OPTION;

FLUSH PRIVILEGES;

Verify the permission:

mysql> SELECT host, user FROM mysql.user; +———–+——————+ | host | user | +———–+——————+ | % | root | | localhost | healthchecker | | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +———–+——————+

Now you can access the mysql from outside of the container using port 3306  from any host.

Obs: This is not a setup for Production use only in your development workstation.

Related Posts

How to Use Podman with the GitHub MCP Server: Fixing the ENOENT Error on IBM Bob

  • 17 Jun, 2026

If you are exploring the new world of the Model Context Protocol (MCP) and trying to install the GitHub MCP server on IBM Bob, there is a good chance the documentation pointed you toward Docker. But w

How to Use Podman with the GitHub MCP Server: Fixing the ENOENT Error on IBM BobRead More

Docker grace period ends on January 31

  • 26 Jan, 2022

I received an email yesterday from Docker. It's a reminder about the end of grace period. Hello, As a reminder you’re receiving this email because on August 31, 2021 we updated the terms(https://ema

Docker grace period ends on January 31Read More

A rootless Pod for wordpress

  • 07 Dec, 2021

Podman Pods are very similar to Kubernetes pods in a way that they can have more than one container. Every Podman pod contains one infra container by default. This container is responsible for associ

A rootless Pod for wordpressRead More