84

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

2
  • 1
    What version of PHP are you pairing with this? I'd bet this is a driver-level issue, as phpMyAdmin is using mysqli. Commented Apr 20, 2018 at 20:23
  • PHP version 7.0.27-0 Commented Apr 23, 2018 at 10:45

18 Answers 18

126

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 *
Sign up to request clarification or add additional context in comments.

10 Comments

Bless you. I wasted a lot of time trying to figure this out. By the way, on MacOS when using phpMyAdmin with Brew, the command I had to run was: ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'secret' (Otherwise I got an "ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%')
I tried these tricks and got it working. Then I moved the folder of mysql, and now the error is back and it work go away. What else cab be wrong?
Please try my updated solution. What do you exactly mean "moved the folder of mysql"?
After entering ALTER USER root IDENTIFIED WITH mysql_native_password BY 'PASSWORD';, I get the following error: ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'. What should I fix here, since I don't allow remote access for root % ?
@Pathros you should ALTER user root@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD'; ... so specify localhost directly
|
34

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

Comments

27
 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpassword'; 

Login through the command line, it will work after that.

2 Comments

Best answer!!!!
I think this works as opposed to the selected answer because of 'root'@'localhost' rather than just root.
18

I solved this issue by doing the following:

  1. Add default_authentication_plugin = mysql_native_password to the
    [mysqld] section of my.cnf
  2. Enter mysql and create a new user by doing something like CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
  3. Grant privileges as necessary. E.g. GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost'; and then FLUSH PRIVILEGES;
  4. Login into phpmyadmin with new user

3 Comments

I tried simply creating a user with mysql_native_password but mysqli still failed to connect. You have to change the default_authentication_plugin for this to work, as described in user1706897's post. I am adding an up-vote to this answer.
@PeteH - did You restart mysql deamon?
I don't believe I restarted the daemon, but it couldn't hurt.
17

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?

5 Comments

Well, when I think about it, it's not really a security issue,because before v8, it always uses mysql_native_password
This ini setting does not even help with MySQL 8.0.11 GA and latest as of today PHPMyAdmin 4.8.0.1. PHPMyAdmin still throws an error: mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
Well, it seems that the changes didn't adopt. Did you restart the MySQL Server and are you sure that there is no other config file?
Yes, restarted service, restarted server, did a fresh install of MySQL 8.0.11 where you can set authentication method in the installer UI. Not helping. I've managed to connect to the newly installed server, and I saw "caching_sha2_password" selected by default for root, under Users and Privileges in Workbench 8.0.11-rc. I assume this is the problem. Per user setting probably overrides default_authentication_plugin config. And the default for root is set to sha2 no matter what during the installation.
Sorry, didn't see your answer. If you updated from an earlier version, maybe you have to update the table structure? This is described in dev.mysql.com/doc/refman/8.0/en/upgrading-strategies.html I just started as described in 8 and 9 a safe server and run mysql_upgrade command. I took a long time....
13

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.

Comments

8

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.

Comments

7

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 

Comments

7

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.

3 Comments

2 days searching for something to fix my issue and this answer finally did it for me. Mac Mojave, using mysql 8 and php 7.2. Thanks!
I still can't get this to work. I ran this query and still can't login. I get the same auth method error. The query doesn't change anything for me? mysql> ALTER user 'root'@'localhost' identified with mysql_native_password by '<root pw>'; Query OK, 0 rows affected (0.01 sec)
ok, turns out I had to use '%' instead of 'localhost', and it'll still say 0 rows affected but it does change it.
5

I solved this issue by doing following:

  1. Enter to system preferences -> mysql

  2. Select "Initialize database" and enter a new root password selecting "Use Legacy Password Encryption".

  3. Login into phpmyadmin with the new password.

1 Comment

The OP did not specify that they are on a Mac; however he told us he installed using apt-get which is Linux. But your answer is for MacOS
5

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!

Comments

3

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.

Comments

2

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; 

Comments

1

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.

Comments

1

I solved this with MySQL 8.0.12 by running:

mysql_upgrade -u root 

Comments

1

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 

Comments

0

I used ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'PASSWORD'; it worked

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.