Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql. The server requested authentication method unknown to the client [caching_sha2_password] #1390

Closed
mvladimir7 opened this issue Feb 23, 2018 · 51 comments

Comments

@mvladimir7
Copy link

mvladimir7 commented Feb 23, 2018

Info:

  • Docker version: 17.12.0-ce, build c97c6d6
  • Laradock commit: 13f55ef
  • 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).

@mvladimir7
Copy link
Author

Root cause

https://mysqlserverteam.com/mysql-8-0-4-new-default-authentication-plugin-caching_sha2_password/

Corrective action

Downgrade mysql version

@RohitVenturit
Copy link

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.

@ondast
Copy link

ondast commented Jul 21, 2018

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.

@undefinedplayer
Copy link

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

@najamalvi
Copy link

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

@MaiQuocDuy
Copy link

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 !!!

@CoderBill
Copy link

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.

@allexiusw
Copy link

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

work for me, thank you!

@MaiQuocDuy
Copy link

MaiQuocDuy commented Oct 27, 2018 via email

@zacksleo
Copy link

zacksleo commented Nov 3, 2018

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']

@Crowbrammer
Copy link

Crowbrammer commented Nov 19, 2018

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

@mostafaznv
Copy link

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

@darlandieterich
Copy link

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

@thpkml
Copy link

thpkml commented Dec 14, 2018

The latest version of mysql :

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

@yeysus
Copy link

yeysus commented Dec 22, 2018

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.

@thicolares
Copy link

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

@stephonfraser
Copy link

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.

@srinivasakumar-a
Copy link

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! :)

@sammysaita
Copy link

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

this really helped me

@leandroruel
Copy link

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

@ivan-khuda
Copy link

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

@vipankumar-JFL
Copy link

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

login through command line, it works after that

@parth11291
Copy link

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??

@leewanvu
Copy link

leewanvu commented Jun 3, 2019

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.

@XorExpr
Copy link

XorExpr commented Aug 22, 2019

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

@Yusov
Copy link

Yusov commented Oct 17, 2019

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.`

@zzkevinlim
Copy link

zzkevinlim commented Oct 31, 2019

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

@ahmadshiddiq
Copy link

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

@djkolka
Copy link

djkolka commented Dec 20, 2019

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';

@StanleyMasinde
Copy link

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

This worked for me. Thank you

@chadyred
Copy link

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

@resham58
Copy link

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.

@brianjohn9527
Copy link

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!!!

@D3M1S22
Copy link

D3M1S22 commented Mar 24, 2020

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.

@sunil-tamang
Copy link

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

@adroutos
Copy link

adroutos commented May 8, 2020

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

That works for me as well!! Thanks brow!

@hackdavid
Copy link

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

@VadneyK
Copy link

VadneyK commented Jun 3, 2020

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

@noveleven
Copy link

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

Amazing😄

@zahangir05
Copy link

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

default-authentication-plugin=mysql_native_password

@sredeck
Copy link

sredeck commented Mar 7, 2021

alter user 'username'@'localhost' identified with mysql_native_password by 'password';

thank you...it worked for me

@aives81
Copy link

aives81 commented Jun 14, 2021

It's work for me too !!
Thank you

@daniaaalarshad
Copy link

Root cause

https://mysqlserverteam.com/mysql-8-0-4-new-default-authentication-plugin-caching_sha2_password/

Corrective action

Downgrade mysql version

Thanks to tell the root of the problem :)

@daniaaalarshad
Copy link

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.

Thankyou so much <3

@GoodJob
Copy link

GoodJob commented Nov 2, 2021

Changing Auth Method for User didn't worked for me, but changing standard Auth method of MySQL 8 - did.

Add lines:
[mysqld]
default-authentication-plugin=mysql_native_password

At the end of:
/etc/mysql/my.cnf

@Rmann-Ngoy
Copy link

Rmann-Ngoy commented Feb 2, 2022

if you are using Mysql 8.0.+ on Mac,

Uninstall Mysql from system preferences
re-install it and choose 'legacy password'
problem solved for me.

@asousajnri
Copy link

asousajnri commented Apr 6, 2023

Worked for me with this https://stackoverflow.com/a/55235533/13922206

@rivolity
Copy link

in mysql 8.4

command: [
      '--character-set-server=utf8mb4',
      '--mysql-native-password=ON',
      '--collation-server=utf8mb4_unicode_ci'
    ]

@alvesrafa
Copy link

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

You saved me, thanks!!

Im running mysql on server and i need to add this variables manually, but is easy:

you need to find your my.cnf and edit

sudo nano /etc/mysql/my.cnf

Add these lines on the end:

[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
default-authentication-plugin=mysql_native_password

Save and restart the service:

sudo systemctl restart mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests