Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql cli to 127.0.0.1 but redirect to 172.17.0.1

Tags:

docker

mysql

I have installed mysql-client in my Mac by the following command:

brew install mysql-client

And when I run the following command:

mysql -h 127.0.0.1 -u root -p 

An ERROR 1045 occured:

ERROR 1045 (28000): Access denied for user 'root'@'172.17.0.1' (using password: NO)

but when I use Sequel Pro I can login the local mysql server.

Why the 127.0.0.1 becomes 172.17.0.1 ?


MORE DETAIL INFO

I run this command on local host iTerm. I use the docker pull to pull a mysql:5.7 image from docker registry:

docker run --name mysql -e MYSQL_ROOT_PASSWORD=xxxxxx -d -p 0.0.0.0:3306:3306 mysql:5.7

And the mysql container is just running, then I use Sequel Pro GUI client to connect into the database in docker, and it works. And then I try to use

brew install mysql-client

to install the mysql command (because I want to use it to run a sql file to prepare data for my project's tests suite). after installed mysql-client, i use the command

mysql -h 127.0.0.1 -u root -p

try to connect database, but it promote the

**ERROR 1045 (28000): Access denied for user 'root'@'172.17.0.1' (using password: NO)**.

I did not do any configuration for the mysql docker container.

like image 338
Bruce Yang Avatar asked Sep 19 '25 09:09

Bruce Yang


1 Answers

After hours try and search, finally I found the solution:

mysql -h 127.0.0.1 -P 3306 -u root -p

you need a -P parameter

like image 183
Bruce Yang Avatar answered Sep 20 '25 22:09

Bruce Yang