how to connect to a docker container running mysql and execute a sql statement

Well, lets 1st create a docker container running my sql (assumes you installed docker).

Here’s how to install a mysql database named example – uses an existing docker container fromt the public registry named atlas-db. Better change your password

docker run --name atlas-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_DATABASE=example mysql

this may hang on you as it is running the container interactive – so you will have to open a new terminal and do this:

docker ps
... lists containers pick your container running "mysql"
docker exec -it [containerID] /bin/bash
mysql -u root -p
-- in mysql databases and schemas are synonymous - yikes!
show databases;

Leave a Comment

Scroll to Top