Hi i am having trouble logging into phpmyadmin on localhost port 8080.
These are the steps i have carried out:
Running an sql container
~$ docker run -d mysql/mysql-server
I then use docker logs to get the generated password.
I ran this command to enter sql:
$ docker exec -it ce9a316 mysql -uroot -p
I then changed the password with this command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'mysql-password';
I then run my phpadmin and link this container to the sql
docker run --name phpmyadmin -d --link ce9a316046f0:db -p 8080:80 phpmyadmin
I am then trying to login to phpmyadmin on port 8080 with username: root and the password set above but it wont let me login. any help is much appricated.
This command fixed the issue:
CREATE USER 'root'#'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%';
I am trying to create a new user but whenever i launch the mysql shell and enter it as the root user using the command
mysql -u root -p
I get an error saying
ERROR 1524 (HY000): Plugin 'root' is not loaded
I solved my problem by adding a new user. step 1 to 3 might not be useful for all.
$ sudo mkdir -p /var/run/mysqld;
$ sudo chown mysql /var/run/mysqld;
$ sudo mysqld_safe --skip-grant-tables &
$ mysql -uroot # "-hlocalhost" is default
try one of these (a) $ sudo mysql -u root -p;
or
(b) $ sudo mysql -u root;
use mysql;
CREATE USER 'jeffrey'#'localhost' IDENTIFIED BY 'mypass';
if USER is already present delete it using -
DROP USER 'test'#'localhost';
this will create a new user . or you can modify the password for the same user.
Option 4 and 5 will help to get you to mysql terminal, once you got there you can solve your issue.
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.
How could I change root password in docker container since the container stop automatically once I stop the mysql service.
Should I stop the mysql container and deploy a new one?
You could change it from a running container, using a docker exec session, as described in "Connecting to MySQL Server from within the Container"
Once the server is ready, you can run the mysql client within the MySQL Server container you just started and connect it to the MySQL Server.
Use the docker exec -it command to start a mysql client inside the Docker container you have started, like this:
docker exec -it mysql1 mysql -uroot -p
When asked, enter the generated root password (see the instructions above on how to find it). Because the MYSQL_ONETIME_PASSWORD option is true by default, after you started the server container with the sample command above and connected a mysql client to the server, you must reset the server root password by issuing this statement for MySQL 5.7 and above :
mysql> update user set authentication_string=password('new_password') where user='root';
or alternatively run,
mysql> SET PASSWORD FOR 'root' = PASSWORD('new_password');
For MySQL 5.7 and older versions, run,
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'newpassword';
Substitute newpassword with the password of your choice. Once the password is reset, the server is ready for use.
Note that the above command will only change the password for 'root' connecting from 'localhost' host. You can verify this by using the command:
select * from mysql.user;
To alter the password for 'root' from all hosts, use:
ALTER USER 'root'#'%' IDENTIFIED BY 'newpassword';
Then, as described in "hub.docker.com/mysql", dont forget docker secrets:
As an alternative to passing sensitive information via environment variables, _FILE may be appended to the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container.
In particular, this can be used to load passwords from Docker secrets stored in /run/secrets/<secret_name> files.
For example:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql-root -d mysql:tag
xeruf points out in the comments to "MYSQL_ROOT_PASSWORD is set but getting "Access denied for user 'root'#'localhost' (using password: YES)" in docker container", adding:
If you mount a volume, make sure to clear it when changing the USER/PASSWORD!
First go to docker container bash using
docker exec -it containerId bash
Then
To Set the new mysql password
mysqladmin -u root -p'oldpassword' password 'newpassword'
To set the password empty use
mysqladmin -u root -p'oldpassword' password ''
Make sure there is no space between -p and oldpassword
In case you forgot the old password, you can reset it following a few steps. I wrote a tutorial on how to do it (you can show you support by giving a few claps): https://medium.com/#marinbinzari/reset-root-mysql-password-in-docker-d961c71285e4
TLDR: create a mysql-init.sql file with the queries to reset the password:
USE mysql;
UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root';
FLUSH PRIVILEGES;
Mount the file in the /tmp folder, run the container (not execute so MySQLD is not started) and then start the mysqld with the init script.
mysqld_safe --init-file=/tmp/mysql-init.sql &
Try to connect, exit the docker container and start using the new password 🤯
Oh, and never forget you password again 😅
You can also set the password at the time of running the container using the -e option, which sets the environment variable MYSQL_ROOT_PASSWORD
docker run -d \
--name=mysql5.7 \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 mysql/mysql-server:latest
To reset the root Password in MYQL 8.0 unfortunatley the upcoming tipp from Martin Binzari does not work anymore completly. But you can do following:
(According his manual and How to reset the root password in MySQL 8.0.11?)
Create a mysql-init.sql
UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
Mount it to /tmp folder.
Stop the container with docker-compose stop mysql
Run docker-compose run mysql bash
Inside run command mysqld_safe --init-file=/tmp/mysql-init.sql &
Wait 10s, press enter and run mysql -uroot
Then you could run command ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
Finally you could exit and login shoud work with new root password.
Here are the steps I followed for accessing the database remotely:
For machine A
sudo apt-get install mysql-server
sudo mysql_install_db
set bind_address=0.0.0.0 on path /etc/mysql/my.cnf
started mysql database on machine A
mysql -u root -p
created a user using following command
create user 'techrocks'#'%' identified by 'myass';
grant all privileges on *.* to 'techrocks'#'%';
flush privileges;
exit mysql and restart mysql, then sudo /etc/init.d/mysql restart
ON machine B I installed mysql-server and then tried to access mysql of machine A
mysql -u techrocks -h ip-address-of-machine-A -p
mysql started but when I tried to create a database as
create database mydb1;
I got access denied error
Access denied for user 'teckrocks'#'%' to database 'mydb1'
Open my.cnf (/etc/mysql/my.cnf)
bind = IP of remote
then try to connect..