Using Docker Desktop, I've started a container of mysql/mysqlserver.
docker run --name=mysqlproject -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server
I then went to create some users for my database.
ALTER USER 'root'#'localhost' IDENTIFIED BY 'password';
create user 'dev'#'%' identified by 'password';
grant select on optim.* to 'dev'#'%';
CREATE USER 'root'#'%' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION
When attempting to connect to my MySQL database from localhost, I was successful
sudo mysql -h 127.0.0.1 -P 3306 -p -u dev
I can also access the MySQL database from MySQL Workbench using the IP4 Address of my Wireless LAN adapter.
However, other users on the LAN cannot access my MYSQL database remotely
ERROR 2003 (HY000): Can't connect to MySQL server on <my Wireless LAN adapter IP> (110)
When looking at the firewall settings in place, I noticed that there was a rule in place blocking TCP traffic to 'Docker Desktop Backend'. Without the privilege to change the rule, I tried starting the container from Ubuntu instead, which is NOT integrated with Docker Desktop, at least according to Resources>WSL Integration.
docker start project
The issue persists - users cannot access my containerized MySQL database remotely.
You need to try with interactive mode from any host, but you should have the ssh key authentication to where the MySQL docker container running.
In my case, sometimes the developers want to access the DB from their local, the below commands help to connect to the DB interactively but the Mysql should listen to the socket path.
ssh -t "host-ip" \
docker run --rm -it \
--volume /db:/db:rw \
--entrypoint "/bin/bash" mysql-docker-image \
-lic /usr/bin/mysql -U username --host /mysql-db-socket-path/run/filename.socket
I need to use MySQL on docker. The steps I've followed :
Installed docker
Pulled MySQL docker image
Ran docker container for MySQL
Installed MySQL client.
But When I run this
sudo docker exec -it mysql8 MySQL -uroot -p
It asks for a password, I enter the password and it gives me this :
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password : Yes)
How do I fix this and what am I missing?
I followed the tutorial here :
https://www.techrepublic.com/article/how-to-deploy-and-use-a-mysql-docker-container/
In order to create a docker container for mysql, you can use this command given below.
docker run -e MYSQL_ROOT_PASSWORD=password -e MYSQL_USER=user -e MYSQL_PASSWORD=password -d -p 3308:3306 -v $HOME/docker/volumes/mysql:/var/lib/mysql mysql
You can also set more environment variables for mysql in this given command.
In order to access mysql inside this container you have 2 easy ways:
Use docker exec -it container_name. Then write mysql -u root -p inside the container or along with the command given is your wish.
Use mysql client and access from local itself.
The article you have followed is outed and also running container and the change password is not the proper way when working in the container. With Offical image, you can set using environment variable.
use below command and further details you can find on Mysql Docker hub.
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mypass -d mysql
then try to connect
docker exec -it some-mysql bash -c "mysql -u root -pmypass"
Found the answer.
Have to run
docker logs <container_name>
which gives a generated password using which we have to use when prompted for password.
Afterward, we can change the password by :
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
I have taken the latest docker image of mysql but I am unable to connect to it from windows host machine.
Executed the following commands:
docker run -p 3306:3306 --hostname=sql --name=mysql_working -d mysql/mysql-server:latest
I can see the IP address with the following command:
docker inspect --format "{{ .NetworkSettings.IPAddress }}" 3ddbeeeb27e9enter
When I do telnet, it is timing out
telnet sql 3306
same for ping
ping <ip address from docker>
Can anyone please advise on whats missing?
You are exposing the port 3306 so the Sql container is available to your host.
If you are on Windows machine type ipconfig
Or for Linux:
ifconfig or ip addr to find your host machine's IP Address and use that IP to connect to Sql.
You can also check docker container logs by docker logs -f container_id here -f is for following the logs.
step1: you need to the changed the default password of MySQL after the first install in docker container
docker logs <container_name or container_id>
docker logs <container_name or container_id> 2>&1 | grep GENERATED
step2:notedown default password
step3:
docker exec -it <container_name or container_id> mysql -uroot -p
Enter default password
ALTER USER 'root'#'localhost' IDENTIFIED BY 'password';
For more info of step1 to step 3 check here
step4:Add new user in mysql as username root and host any with password
create user 'root'#'%' identified by 'password';
step5:Grant all permission to that user
grant all privileges on *.* to 'root'#'%' with grant option;
For more info of step4 to step 5 check here
step 6: Exit from docker container: press ctrl+p+q keys (not plus key combination of ctrl with p and q)
step7: suppose you are on hostmachine then
(else you give ipaddress of hostmachine instead of localhost)
telenet -l root localhost 3306
It asks for password enter password (we given password as password in step4)
press ctrl+] key (not plus key combination of ctrl with ])
Telent connect successfully ..!!
How to access the MySQL server running on a Docker container in a remote machine.
Here is my dockerfile:
MAINTAINER debu_bbsr#yahoo.com
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server \
&& sed -i "s/127.0.0.1/0.0.0.0/g" /etc/mysql/mysql.conf.d/mysqld.cnf \
&& mkdir /var/run/mysqld \
&& chown -R mysql:mysql /var/run/mysqld
VOLUME ["/var/lib/mysql"]
EXPOSE 3306
CMD ["mysqld_safe"]
I created an image:
sudo docker build -t deb_mysql_image .
Run the Docker container with the above image:
sudo docker run -i -t -d -p 3306:3306 --name mysql_deb_container deb_mysql_image
Enter into the MySQL container:
`k8smaster#k8smaster:~/debashish$ sudo docker exec -it mysql_deb_container mysql`
Create different users and database:
mysql> create user debashish identified by 'debashish';
mysql> create user debmysql identified by 'debmysql';
mysql> create database debdb;
mysql> use debdb;
Grant privileges to the users and create a table:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'debashish' WITH GRANT OPTION;
CREATE TABLE debtbl1 (name VARCHAR(20), address VARCHAR(50));
Populate the table:
insert into debtbl1 values('Debashish', 'Shanghai');
insert into debtbl1 values('Debu', 'Livingston, Shanghai');
Now access the contents of the above MySQL table from a remote machine with the MySQL client:
k8snode1#k8snode1:~$ mysql -u 'debashish' -p -h 10.10.10.2 -P 3306 -D debdb
Enter password
"Sometimes" I encounter the issue -
ERROR 1045 (28000): Access denied for user
Anything am I missing to make it a robust system so I dont encounter "sometimes" the above error.
Most likely your user doesn't have permissions to access from that server, either grant privileges for that specific server or globally.
Run:
GRANT ALL PRIVILEGES ON *.* TO 'debashish'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
The issue was that - whenever a Pod was restarted, all the privileges assigned to the Mysql DB also gets erased.
Hence the solution was to - write a shell script that will be:
1. Executed when the Pod is started/scaled-in/container is started.
2. The shell script automatically creates the database and users.
3. Shell script then grants permission to the users for the DB.
This question already has answers here:
Access denied after setting user's password with SHA256 in phpMyAdmin
(3 answers)
Closed 3 years ago.
UPDATE
Newer versions of phpMyAdmin solved this issue. I've successfully tested with phpMyAdmin 5.0.1
I have installed the MySQL 8.0 server and phpMyAdmin, but when I try to access it from the browser the following errors occur:
#2054 - The server requested authentication method unknown to the client
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
I imagine it must have something to do with the strong passwords implemented and the relative freshness of the MySQL release.
But I know nothing of the most advanced driver and connection configuration.
Has someone faced the same problem and solved it? :D
Log in to MySQL console with root user:
root#9532f0da1a2a:/# mysql -u root -pPASSWORD
and change the Authentication Plugin with the password there:
mysql> ALTER USER root IDENTIFIED WITH mysql_native_password BY 'PASSWORD';
Query OK, 0 rows affected (0.08 sec)
You can read more info about the Preferred Authentication Plugin on the MySQL 8.0 Reference Manual
https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
It is working perfectly in a dockerized environment:
docker run --name mysql -e MYSQL_ROOT_PASSWORD=PASSWORD -p 3306:3306 -d mysql:latest
docker exec -it mysql bash
mysql -u root -pPASSWORD
ALTER USER root IDENTIFIED WITH mysql_native_password BY 'PASSWORD';
exit
exit
docker run --name phpmyadmin -d --link mysql:db -p 8080:80 phpmyadmin/phpmyadmin:latest
So you can now log in to phpMyAdmin on http://localhost:8080 with root / PASSWORD
mysql/mysql-server
If you are using mysql/mysql-server docker image
But remember, it is just a 'quick and dirty' solution in the development environment. It is not wise to change the MySQL Preferred Authentication Plugin.
docker run --name mysql -e MYSQL_ROOT_PASSWORD=PASSWORD -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server:latest
docker exec -it mysql mysql -u root -pPASSWORD -e "ALTER USER root IDENTIFIED WITH mysql_native_password BY 'PASSWORD';"
docker run --name phpmyadmin -d --link mysql:db -p 8080:80 phpmyadmin/phpmyadmin:latest
Updated solution at 10/04/2018
Change the MySQL default authentication plugin by uncommenting the default_authentication_plugin=mysql_native_password setting in /etc/my.cnf
use at your own risk
docker run --name mysql -e MYSQL_ROOT_PASSWORD=PASSWORD -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server:latest
docker exec -it mysql sed -i -e 's/# default-authentication-plugin=mysql_native_password/default-authentication-plugin=mysql_native_password/g' /etc/my.cnf
docker stop mysql; docker start mysql
docker run --name phpmyadmin -d --link mysql:db -p 8080:80 phpmyadmin/phpmyadmin:latest
Updated workaround at 01/30/2019
docker run --name mysql -e MYSQL_ROOT_PASSWORD=PASSWORD -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql/mysql-server:latest
docker exec -it mysql sed -i -e 's/# default-authentication-plugin=mysql_native_password/default-authentication-plugin=mysql_native_password/g' /etc/my.cnf
docker exec -it mysql mysql -u root -pPASSWORD -e "ALTER USER root IDENTIFIED WITH mysql_native_password BY 'PASSWORD';"
docker stop mysql; docker start mysql
docker run --name phpmyadmin -d --link mysql:db -p 8080:80 phpmyadmin/phpmyadmin:latest
default_authentication_plugin
Updated solution at 09/13/2021
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
exactly with quotes *
New MySQL 8.0.11 is using caching_sha2_password as default authentication method. I think that phpMyAdmin cannot understand this authentication method.
You need to create user with one of the older authentication method, e.g. CREATE USER xyz#localhost IDENTIFIED WITH mysql_native_password BY 'passw0rd'.
More here https://dev.mysql.com/doc/refman/8.0/en/create-user.html and here https://dev.mysql.com/doc/refman/8.0/en/authentication-plugins.html
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpassword';
Login through the command line, it will work after that.
I solved this issue by doing the following:
Add default_authentication_plugin = mysql_native_password to the
[mysqld] section of my.cnf
Enter mysql and create a new user by doing something like CREATE USER
'root'#'localhost' IDENTIFIED BY 'password';
Grant privileges as necessary. E.g. GRANT ALL PRIVILEGES ON * . * TO
'root'#'localhost'; and then FLUSH PRIVILEGES;
Login into phpmyadmin with new user
Another idea: as long as the phpmyadmin and other php tools don't work with it, just add this line to your file /etc/mysql/my.cnf
default_authentication_plugin = mysql_native_password
See also:
Mysql Ref
I know that this is a security issue, but what to do if the tools don't work with caching_sha2_password?
I went to system
preferences -> mysql -> initialize database -> use legacy password encryption(instead of strong) -> entered same password
as my config.inc.php file, restarted the apache server and it worked. I was still suspicious about it so I stopped the apache and mysql server and started them again and now it's working.
I solved my problem basically with András answer:
1- Log in to MySQL console with root user:
root#9532f0da1a2a:/# mysql -u root -pPASSWORD
And type the root's password to auth.
2- I created a new user:
mysql> CREATE USER 'user'#'hostname' IDENTIFIED BY 'password';
3- Grant all privileges to the new user:
mysql> GRANT ALL PRIVILEGES ON *.* To 'user'#'hostname';
4- Change the Authentication Plugin with the password:
mysql> ALTER USER user IDENTIFIED WITH mysql_native_password BY 'PASSWORD';
Now, phpmyadmin works fine logging the new user.
To fix this issue I just run one query in my mysql console.
For this login to mysql console using this
mysql -u {username} -p{password}
After this I just run one query as given below:-
ALTER user '{USERNAME}'#'localhost' identified with mysql_native_password by '{PASSWORD}';
when I run this query I got message that query executed. Then login to PHPMYADMIN with username/password.
If you are using the official mysql docker container, there is a simple solution:
Add the following line to your docker-compose service:
command: --default-authentication-plugin=mysql_native_password
Example configuration:
mysql:
image: mysql:8
networks:
- net_internal
volumes:
- mysql_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=db
command: --default-authentication-plugin=mysql_native_password
I solved this issue by doing following:
Enter to system preferences -> mysql
Select "Initialize database" and enter a new root password selecting "Use Legacy Password Encryption".
Login into phpmyadmin with the new password.
I had this problem, did not find any ini file in Windows, but the solution that worked for me was very simple.
1. Open the mysql installer.
2. Reconfigure mysql server, it is the first link.
3. Go to authentication method.
4. Choose 'Legacy authentication'.
5. Give your password(next field).
6. Apply changes.
That's it, hope my solution works fine for you as well!
As #kgr mentioned, MySQL 8.0.11 made some changes to the authentication method.
I've opened a phpMyAdmin bug report about this: https://github.com/phpmyadmin/phpmyadmin/issues/14220.
MySQL 8.0.4-rc was working fine for me, and I kind of think it's ridiculous for MySQL to make such a change in a patch level release.
Create another user with mysql_native_password option:
In terminal:
mysql> CREATE USER 'su'#'localhost' IDENTIFIED WITH mysql_native_password BY '123';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'su'#'localhost';
mysql> FLUSH PRIVILEGES;
As many pointed out in other answers, changing the default authentication plugin of MySQL to native does the trick.
Still, since I can't use the new caching_sha2_password plugin, I'll wait until compatibility is developed to close the topic.
I solved this with MySQL 8.0.12 by running:
mysql_upgrade -u root
in my case, to fix it I preferred to create a new user to use with PhpMyAdmin because modifying the root user has caused native login problems with other applications such as MySQL WorkBench.
This is what I did:
Log in to MySQL console with root user: mysql -u root -p, enter your password.
Let’s create a new user within the MySQL shell:
CREATE USER 'newMySqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlNewUsernamePassword';
At this point the newMysqlUsername has no permissions to do anything with the databases. So is needed to provide the user with access to the information they will need.
GRANT ALL PRIVILEGES ON * . * TO ' newMySqlUsername'#'localhost';
Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.
FLUSH PRIVILEGES;
Log out by typing quit or \q, and your changes will now be in effect, we can log in into PhpMyAdmin with the new user and it will have access to the databases.
Also you can log back in with this command in terminal:
mysql -u newMySqlUsername -p
I used ALTER USER root#localhost IDENTIFIED WITH mysql_native_password BY 'PASSWORD'; it worked
You can change the Authentication if u are running on Windows by reconfiguring the installation by running the msi. It will ask for changing the default authentication to legacy, then u can proceed with that option to change the authentication to the legacy one.