Connect to the MySQL on Docker with CMD

I connect to the bash into the running MySQL container:

$ docker exec -t -icontainer_mysql_name/bin/bash

-i is the shortcut for --interactive option. This options is used for keep STDIN open even if not attached

-t is the shortcut for --tty option, used to allocate a pseudo-TTY

I run MySQL client from bash MySQL container:

$ mysql -uroot -proot

-u is shortcut for --user=name option, used to define user for login if not current user.

-p is shortcut for -password[=name] option, used to define password to use when connecting to server. If password is not given it’s asked from the tty.


$ docker exec -t -i container_mysql_name /bin/bash -c "mysql -uroot -proot"

Mysql: How to get size of mysql database?

Run this query and you’ll probably get what you’re looking for:

SELECT table_schema                                        "DB Name", 
   Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
FROM   information_schema.tables 
GROUP  BY table_schema;