Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JorisNienkemper/800a9a60222fa24b23fdffa13a4c6ccd to your computer and use it in GitHub Desktop.
Save JorisNienkemper/800a9a60222fa24b23fdffa13a4c6ccd to your computer and use it in GitHub Desktop.
install start and connect with java to docker-mysql
#create docker container mysql8
docker run --name mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pAssw0rd -e MYSQL_DATABASE=cursistdb
-e MYSQL_USER=cursist -e MYSQL_PASSWORD=pAssw0rd -d mysql:latest
docker logs -f mysql8
#Look in the logs for creation of database cursistdb with user cursist and password pAssw0rd
#From the log
#Creating database cursistdb
#Creating user cursist
#Giving user cursist access to schema cursistdb
# Ctrl-C to end docker logs
# start bash shell to use mysql client in the container
Johns-MacBook-Pro:~ john$ docker exec -it mysql8 bash
root@ed8414a90c50:/# whoami -> root
root@ed8414a90c50:/# mysql -u cursist -p
Enter password:
Welcome to the MySQL monitor....
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases ;
+--------------------+
| Database |
+--------------------+
| cursistdb |
| information_schema |
+--------------------+
2 rows in set (0.01 sec)
mysql> CREATE TABLE cursist(....);
mysql> exit
Bye
root@ed8414a90c50:/# exit
exit
Johns-MacBook-Pro:~ john$
#Useful command to get runtime information about the container
docker ps
docker inspect mysql8
#Stop the container
docker stop mysql8
#Remove the container
docker rm mysql8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment