[Docker] Start a local MySQL container for testing

Created on November 30, 2026

This example starts MySQL 8.0.23 in Docker. The command uses sudo on an Ubuntu setup.

sudo docker run -e MYSQL_ROOT_PASSWORD=password -P -d mysql:8.0.23
  • -e MYSQL_ROOT_PASSWORD=password sets an example password for the MySQL root account.
  • -P automatically publishes exposed container ports on available host ports.
  • -d runs the container in the background.

Check the host port mapped to the container's MySQL port 3306. Once MySQL is ready, connect over TCP. In this example the assigned host port is 32769.

mysql -uroot -ppassword -P 32769 -h 127.0.0.1
Docker MySQL