From time to time there is the need to log into a containerized MySQL instance. And of course, when this time comes, I have completely forgotten how this works. Consequently, I should write it down. Here you go:
Bash into the running container
docker exec -t -i <container_id> /bin/bash
Usually, you should end up with something like the following:
root@localhost:~# docker exec -t -i 365a8a95c335 /bin/bash
root@365a8a95c335:/#
Log into MySQL
mysql -u “<useranme>” -p
Once again, it should look similar to the following:
root@365a8a95c335:/# mysql -u "wpuser" -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 146
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement
mysql>
Now you should be able to do whatever you want to do with MySQL.