(It\'s probably a dumb question due to my limited knowledge with Docker or mysql administration, but since I spent a whole evening on this issue, I dare to ask it.)
In your terminal run: docker exec -it container_name /bin/bash
Then: mysql
For conversion,you can create ~/.my.cnf
file in host:
[Mysql]
user=root
password=yourpass
host=127.0.0.1
port=3306
Then next time just run mysql
for mysql client to open connection.
change "localhost" to your real con ip addr
because it's to mysql_connect()
The simple method is to share the mysql unix socket to host machine. Then connect through the socket
Steps:
mkdir /host
docker run -it -v /host:/shared <mysql image>
./etc/my.cnf
and change socket entry in the file to socket=/shared/mysql.sock
service mysql restart
in dockermysql -u root --socket=/host/mysql.sock
. If password use -p optiondocker run -e MYSQL_ROOT_PASSWORD=pass --name sql-db -p 3306:3306 mysql
docker exec -it sql-db bash
mysql -u root -p
I was able to connect my sql server5.7 running on my host using the below command : mysql -h 10.10.1.7 -P 3307 --protocol=tcp -u root -p where the ip given is my host ip and 3307 is the port forwaded in mysql docker .After entering the command type the password for myql.that is it.Now you are connected the mysql docker container from the you hostmachine