I created a MySQL server docker instance using the following command:
[me#centos7 ~]$ docker run --name mysql_db -p 6604:3306 -e MYSQL_ROOT_HOST='%' -e MYSQL_ROOT_PASSWORD='jose' -d mysql/mysql-server:5.7
3d7d2c6231cbc2a8f96d1c965588c4349113c18aa01c8322dc79c670d6d02105
When I try to connect to the server, I get the following error:
[me#centos7 ~]$ mysql -uroot -pjose -h localhost -P6604
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
How should I fix my commands to be able to connect to the server instance using my local MySQL client?
you can read about bind-address
sudo lsof -i -P -n | grep LISTEN
docker-pr 673318 root 4u IPv4 8564315 0t0 TCP *:6604 (LISTEN)
try
mysql -uroot -pjose -h 0.0.0.0 -P6604
Related
I try connect my mysql host DB from docker container by using host mode and I get the error:
docker run --rm -it --network=host mysql mysql -h 127.0.0.1 -utestuser -p
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
The base of my work is stackoverflow-answer https://stackoverflow.com/a/24326540/1514029
My host mysql version is 8.0.25.
I tried in my.cnf bind-address = 0.0.0.0 and bind-address = 172.17.42.1
Every binding have the same problem.
I grant the testuser user access to 127.0.0.1 by statements
CREATE USER testuser#127.0.0.1 IDENTIFIED BY 'blah'
grant all privileges on *.* to testuser#127.0.0.1 with grant option
On docker bridge mode my connection work fine only on docker host mode it fails!
It must be a network problem!?
you can use:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.25
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.
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
I am trying to connect to mysql server using mysql cli. Image was created using following command:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d mysql
The docker container is running. docker ps prints:
johnd#john-pc:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
598c0f8680dc mysql "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp some-mysql
When i enter the following command:
mysql -h 127.0.0.1 -P 3306 -u root -p it returns:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
I also tried with --protocol=tcp attribute. How do i connect from client to mysql server running on docker using terminal from client machine (not from another docker)
EDIT:
I also tried connecting to mysql using this command:
docker run -it --rm mysql mysql -h127.0.0.1 -uexample-user -p
It returns the same error
mysql -h 127.0.0.1 -P 3306 -u root -p
You are connecting to your localhost's sql server but you didn't map the docker's container port to the host.
Try mapping the port to your host by this:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d -p 3306:3306 mysql
Then retry:
mysql -h 127.0.0.1 -P 3306 -u root -p
same error to me, just remember start mysql service first in your container.
exec in your container
/etc/init.d/mysql start
Using internal docker IP like 127.0.0.1 didn't work for me
I used my POD's IP and it worked
mysql -h 10.10.10.41 -P 3306 -u root -p
I still don't understand why I wasn't able to login and before and after this command I was able to login
I'm trying to install/configure phpmyadmin using docker inside Ubuntu 14.04. I started like this:
docker run --name myadmin -d -e PMA_HOST=localhost -e PMA_PORT=3306 -p 8282:80 phpmyadmin/phpmyadmin
When I try to login I get the following error:
#2002 - Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory") — The server is not responding (or the local server's socket is not correctly configured).
mysqli_real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")
The MySQL server is installed directly in Ubuntu not in docker.
Any ideas?
You cannot use localhost in your docker container.
docker run --rm --name myadmin -it -e PMA_HOST=172.17.0.1 -e PMA_PORT=3306 -p 8282:80 phpmyadmin/phpmyadmin
Where 172.17.0.1 is my host ip of the docker0 bridge.
This is what worked for me:
Check you have your db up and running:
"service mysql status" or "systemctl status mysqld"
(It should say active(running))
Run phpMyAdmin in a container:
docker run --name="phpMyAdmin-local" -itd -e PMA_HOST=$(ip route show | grep docker0 | awk '{print $9}') -p 8283:80 phpmyadmin/phpmyadmin
Check container is up and running:
docker ps -a
(check phpMyAdmin-local status is up)
Go to "localhost:8283" and check phpMyAdmin is there
Let your db receive external requests:
Edit file as sudo:
MariaDb:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
MySQL:
nano /etc/mysql/my.cnf
(nano is the text editor and can be changed)
and change this line:
bind-address = 127.0.0.1
To this line: (note the "#")
# bind-address = 127.0.0.1
(ctrl+x to exit, "y" to save it and "enter" to confirm)
Give permision to users/user to connect from a different location (different from localhost):
Modify users and login to mysql/mariadb cli with root privileges:
mysql -uroot -p -P3306
(enter password after running command)
Use mysql database to edit users:
use mysql;
Give pribvileges to specific user: (can be different from root if you have other users):
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Then:
FLUSH PRIVILEGES;
and:
exit;
Restart mysql service:
service mysqld stop
service mysqld start
And now you would be able to login to phpMyAdmin with the user and password you specify in prev. commands and mysql/mariadb would accept connections.
For mac OS users, use host.docker.internal as the host address which docker will resolve to the host's IP address.
docker run --rm --name myadmin -it -e PMA_HOST=host.docker.internal -e PMA_PORT=3306 -p 8282:80 phpmyadmin/phpmyadmin
Instead of connecting through socket file try to connect using IP (127.0.0.1) and for PMA port use your machine IP which you can get through ifconfig command.
I'm using https://github.com/sameersbn/docker-mysql to run a mysql container using docker-machine in OSX with virtualbox.
I created a new machine
docker-machine create --driver virtualbox mytest
The IP is
docker-machine ip mytest
192.168.99.103
I run the container like this:
docker run -p 3306:3306 --name mysql -d \
-v /opt/mysql/data:/var/lib/mysql \
-e 'DB_USER=sampleuser' -e 'DB_PASS=samplepass' -e 'DB_NAME=sampledb' -e 'DB_REMOTE_ROOT_NAME=root' -e 'DB_REMOTE_ROOT_PASS=samplerootpass' \
sameersbn/mysql:latest
Now, when I try to connect to the mysql in the container from my hostmachine I can connect using user sampleuser but not as user root.
▶ mysql -u root -p -h 192.168.99.103
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'192.168.99.1' (using password: YES)
192.168.99.1 is my local laptops ip address
▶ ifconfig | grep "192"
inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255
By default, root only has access from the localhost, 127.0.0.1 & ::1, you need to specifically allow access from 192.168.99.1 or from anywhere using '%' in the user setup : see here http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html