Laradock: Mysql. The server requested authentication method unknown to the client [caching_sha2_password]

Created on 23 Feb 2018  Â·  42Comments  Â·  Source: laradock/laradock

Info:

  • Docker version: 17.12.0-ce, build c97c6d6
  • Laradock commit: 13f55ef7967989337ed3538af3a8164268eeb623
  • System info: Win
  • System info disto/version: 10

Issue:

New fresh laradock installation. All default settings. Driver is shared.
Except:

DATA_SAVE_PATH=../../data

Can't connect to the mysql from phpMyAdmin.
image

#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

But I can connect to mysql inside mysql container with standard root/root credentials.

I tried to delete all containers and images. Several times downloaded laradock. Tried to reinstall Docker. No success.


Expected behavior:

Can connect to mysql with phpMyAdmin


Logs

$ docker logs laradock_mysql_1
2018-02-23T13:22:10.682788Z 0 [Warning] [MY-011070] Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it is deprecated and will be removed in a future release.
2018-02-23T13:22:10.682938Z 0 [Warning] [MY-010915] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-02-23T13:22:10.695441Z 0 [System] [MY-010116] /usr/sbin/mysqld (mysqld 8.0.4-rc-log) starting as process 1 ...
mbind: Operation not permitted
mbind: Operation not permitted
2018-02-23T13:22:11.537504Z 0 [Warning] [MY-010068] CA certificate ca.pem is self signed.
2018-02-23T13:22:11.542367Z 0 [Warning] [MY-000000] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2018-02-23T13:22:11.549449Z 0 [Warning] [MY-010315] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.549556Z 0 [Warning] [MY-010315] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.549594Z 0 [Warning] [MY-010315] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.549629Z 0 [Warning] [MY-010315] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.549676Z 0 [Warning] [MY-010323] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.549727Z 0 [Warning] [MY-010323] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.549779Z 0 [Warning] [MY-010311] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.565161Z 0 [Warning] [MY-010330] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.565260Z 0 [Warning] [MY-010330] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-02-23T13:22:11.570621Z 0 [System] [MY-010931] /usr/sbin/mysqld: ready for connections. Version: '8.0.4-rc-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL).

Most helpful comment

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

All 42 comments

Don't uninstall MySQL latest version. Rather follow these steps https://gist.github.com/benlinton/d24471729ed6c2ace731
Basically you need to unlink latest installed mysql, install older MSQL version and link it.

If you want to use mysql 8 with native password (the old way) you can follow the following steps:

Add this to my.cnf in laradock\mysql\my.cnf under [mysqld]:
default-authentication-plugin=mysql_native_password
Clear the data-folder (will destroy your data), rebuild the mysql container and it should work.

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

alter user 'username'@'localhost' identified with mysql_native_password by 'password';
Bravoo. This is the solution

Hi Mr. Ailionx and Mr. Najamalvi,
I'm a student in a country which don't speak English. I'm very happy when reading your guide but I don't understand what steps I should do. Please tell me more details. Thank so much !!!

Don't uninstall MySQL 8. Sign into mysql using a terminal program:
mysql -u root -p
my_password
alter user 'username'@'localhost' identified with mysql_native_password by 'password';

This does the trick.

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

work for me, thank you!

It also work for me. Many many thanks for you. Have a nice day!!!
On Sat, Oct 27, 2018 at 9:55 AM William Alexander notifications@github.com
wrote:

alter user 'username'@'localhost' identified with mysql_native_password
by 'password'; would fix it.

work for me, thank you!

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/laradock/laradock/issues/1390#issuecomment-433585330,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AqZUP-QX0NTNn9J98RuhesSqjAuiuGnWks5uo8s6gaJpZM4SQ5gP
.

added these lines in docker-compose.yml fixed my issue:

    mysql:
        image: mysql:8
        command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']

Basic PDO user with a possible solution. You do not have to uninstall MySQL 8.x or even do the above (maybe... I'm not using Laradock). You just need to go to your MySQL installer, reconfigure your server, and select Legacy Authentication Method (which retains MySQL 5.x compatibility). I figured this out through trial and error after my dsn in my PDO didn't allow me to connect.

Finding the Installer in Windows
Click 'Reconfigure'
Select the bottom option

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

you saved my life.
I changed default auth plugin to mysql native password in /etc/my.cnf and then used your command.
my problem solved

if external/remote use replace 'localhost' to '%'

The latest version of mysql :

initialize database
choose 'legacy password'
problem solved for me
simples (unless I face more issues later ;) )

added these lines in docker-compose.yml fixed my issue:

    mysql:
        image: mysql:8
        command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']

You just saved my life @zacksleo, Thanks. Installing latest drupal 8.6.4 with MySQL 8.0.13 both via docker.

If you want to use mysql 8 with native password (the old way) you can follow the following steps:

Add this to my.cnf in laradock\mysql\my.cnf under [mysqld]:
default-authentication-plugin=mysql_native_password
Clear the data-folder (will destroy your data), rebuild the mysql container and it should work.

Just in case someone else is using laradock too, by "clear the data-folder" I guess is:

   $ rm -rf ~/.laradock/data

Don't uninstall MySQL 8. Sign into mysql using a terminal program:
mysql -u root -p
my_password
alter user 'username'@'localhost' identified with mysql_native_password by 'password';

This does the trick.

I'm using windows and I don't know which terminal program I should use for this. I really need help on this.

Basic PDO user with a possible solution. You do not have to uninstall MySQL 8.x or even do the above (maybe... I'm not using Laradock). You just need to go to your MySQL installer, reconfigure your server, and select Legacy Authentication Method (which retains MySQL 5.x compatibility). I figured this out through trial and error after my dsn in my PDO didn't allow me to connect.

Finding the Installer in Windows
Click 'Reconfigure'
Select the bottom option

thanks a lot for your work around and it worked for me! :)

alter user 'username'@'localhost' identified with mysql_native_password by 'password';
Bravoo. This is the solution

this really helped me

just remove damn mysql and use mariadb 10.x as main database, it works fine.

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; This one helps me. Thank you!

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

login through command line, it works after that

Access denied for user 'root'@'localhost' (using password: YES)

i have already used ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpassword';

what to do now??

If you want to use mysql 8 with native password (the old way) you can follow the following steps:
Add this to my.cnf in laradock\mysql\my.cnf under [mysqld]:
default-authentication-plugin=mysql_native_password
Clear the data-folder (will destroy your data), rebuild the mysql container and it should work.

Just in case someone else is using laradock too, by "clear the data-folder" I guess is:

   $ rm -rf ~/.laradock/data

@thicolares Thanks so much. You save my life.

Basic PDO user with a possible solution. You do not have to uninstall MySQL 8.x or even do the above (maybe... I'm not using Laradock). You just need to go to your MySQL installer, reconfigure your server, and select Legacy Authentication Method (which retains MySQL 5.x compatibility). I figured this out through trial and error after my dsn in my PDO didn't allow me to connect.

Finding the Installer in Windows
Click 'Reconfigure'
Select the bottom option

Worked fine! Thank you

If you want to use mysql 8 with native password (the old way) you can follow the following steps:
Add this to my.cnf in laradock\mysql\my.cnf under [mysqld]:
default-authentication-plugin=mysql_native_password
Clear the data-folder (will destroy your data), rebuild the mysql container and it should work.

Just in case someone else is using laradock too, by "clear the data-folder" I guess is:

   $ rm -rf ~/.laradock/data

This is working, but to clarify the things a bit:

  • if you don't find the .laradock folder and you are on Windows look in the C:\Users\YourProfileName, it should be there, on Linux try the logged user's folder (root if you logging in with it)
  • build with docker-compose build --no-cache mysql and restart containers (down & up)
  • don't forget to login in phpmyadmin with mysql/root/root or whatever you have in your .env file (mysql/default/secret)

Don't uninstall MySQL 8. Sign into mysql using a terminal program:
mysql -u root -p
my_password
alter user 'username'@'localhost' identified with mysql_native_password by 'password';

This does the trick.

well done! thanks

if you use mysql latest version in docker container, you can type this command into docker-compose.yaml command: --default-authentication-plugin=mysql_native_password

mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306:3306

or use oldest version mysql.`

This worked for me on CentosOS.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';

source: https://stackoverflow.com/questions/52364415/php-with-mysql-8-0-error-the-server-requested-authentication-method-unknown-to

This worked for me on CentosOS.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';

source: https://stackoverflow.com/questions/52364415/php-with-mysql-8-0-error-the-server-requested-authentication-method-unknown-to

This works very well for me :D

Its work for me !!!
Don't uninstall MySQL 8. Sign into mysql using a terminal program:
mysql -u root -p
my_password
alter user 'username'@'localhost' identified with mysql_native_password by 'password';

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

This worked for me. Thank you

And actually with docker-compose.yaml

version: "3"
services:
  database:
    image: mysql:8.0.19
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test

This worked for me on CentosOS.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';

source: https://stackoverflow.com/questions/52364415/php-with-mysql-8-0-error-the-server-requested-authentication-method-unknown-to

This worked for me. Thank You.

Basic PDO user with a possible solution. You do not have to uninstall MySQL 8.x or even do the above (maybe... I'm not using Laradock). You just need to go to your MySQL installer, reconfigure your server, and select Legacy Authentication Method (which retains MySQL 5.x compatibility). I figured this out through trial and error after my dsn in my PDO didn't allow me to connect.

Finding the Installer in Windows
Click 'Reconfigure'
Select the bottom option

This really helps me fix my problem! Thanks for sharing!!!

For Mac users, just go to System Preference, MySql panel, initialize Database, if use "strong password encryption" is selected choose "Use Legacy Password encryption", insert the root password and then click ok. It will require your pc password. Thats all.

or You can follow this video if you want or reset mysql password
https://www.youtube.com/watch?v=T5wg7ekMje0

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

That works for me as well!! Thanks brow!

if you are facing "caching_sha2_password" error during connectivity of your mysql database using python ,
go through this
https://www.youtube.com/watch?v=YNq-EuQEJos

You can also fix this issue using phpmyadmin:
navigate to users->
change password->
enter your new password
make sure to select "Native MYSQL authentication" on the drop down "password hashing" menu

alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it.

Amazing😄

Add following line under [mysqld] of your mysql configuration file, so called my.cnf

default-authentication-plugin=mysql_native_password

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ejblom picture ejblom  Â·  3Comments

sixlive picture sixlive  Â·  3Comments

StarFleetCPTN picture StarFleetCPTN  Â·  3Comments

nickfan picture nickfan  Â·  3Comments

Mahmoudz picture Mahmoudz  Â·  3Comments