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/bashroot@365a8a95c335:/#
Log into MySQL
mysql -u “<useranme>” -p
Once again, it should look similar to the following:
root@365a8a95c335:/# mysql -u "wpuser" -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 146Server version: 5.7.24 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reservedOracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective ownersType 'help;' or '\h' for help. Type '\c' to clear the current input statementmysql>
Now you should be able to do whatever you want to do with MySQL.