Java 如何解决无法加载身份验证插件“caching_sha2_password”问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50387952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve Unable to load authentication plugin 'caching_sha2_password' issue
提问by Sarath Mohan
In eclipse when i started my application i got this - Could not discover the dialect to use. java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.
在 Eclipse 中,当我启动我的应用程序时,我得到了这个 - 无法发现要使用的方言。java.sql.SQLException:无法加载身份验证插件“caching_sha2_password”。
at java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'. at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:868) at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:864) at at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746) at at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226) at at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2191) at at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2222) at at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017) at at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:779) at at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47) at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at at java.lang.reflect.Constructor.newInstance(Unknown Source) at at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389) at at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) at at java.sql.DriverManager.getConnection(Unknown Source) at at java.sql.DriverManager.getConnection(Unknown Source) at at ch.qos.logback.core.db.DriverManagerConnectionSource.getConnection(DriverManagerConnectionSource.java:54) at at ch.qos.logback.core.db.ConnectionSourceBase.discoverConnectionProperties(ConnectionSourceBase.java:46) at at ch.qos.logback.core.db.DriverManagerConnectionSource.start(DriverManagerConnectionSource.java:38) at at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:161) at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309) at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193) at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179) at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53) at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75) at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150) at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84) at at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:55) at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412) at at ch.qos.logback.classic.util.StatusViaSLF4JLoggerFactory.addStatus(StatusViaSLF4JLoggerFactory.java:32) at at ch.qos.logback.classic.util.StatusViaSLF4JLoggerFactory.addInfo(StatusViaSLF4JLoggerFactory.java:20) at at ch.qos.logback.classic.servlet.LogbackServletContainerInitializer.onStartup(LogbackServletContainerInitializer.java:32) at at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245) at at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421) at at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411) at at java.util.concurrent.FutureTask.run(Unknown Source) at at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at at java.lang.Thread.run(Unknown Source)
在 java.sql.SQLException:无法加载身份验证插件“caching_sha2_password”。在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:868) 在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:864) 在 com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO. java:1746) 在 com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226) 在 com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2191) 在 com.mysql.jdbc.ConnectionImpl。 connectOneTryOnly(ConnectionImpl.java:2222) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:779) at com.mysql.jdbc .JDBC4Connection.(JDBC4Connection.java:47) 在 sun.reflect.NativeConstructorAccessorImpl。
回答by Sarath Mohan
You are having issue with newly MySQL version that came with "caching_sha2_password" plugin, follow the below command to get it resolved.
您在使用“caching_sha2_password”插件附带的新 MySQL 版本时遇到问题,请按照以下命令解决问题。
DROP USER 'your_user_name'@'%';
CREATE USER 'your_user_name'@'%' IDENTIFIED WITH mysql_native_password BY 'your_user_password';
GRANT ALL PRIVILEGES ON your_db_name.* TO 'your_user_name'@'%' identified by 'your_user_password';
Or you can just use the below command to keep your privileges as it is:
或者您可以使用以下命令来保持您的特权:
ALTER USER your_user_name IDENTIFIED WITH mysql_native_password;
回答by Gaurav
Starting with MySQL 8.0.4, they have changed the default authentication plugin for MySQL server from mysql_native_passwordto caching_sha2_password.
从 MySQL 8.0.4 开始,他们将 MySQL 服务器的默认身份验证插件从mysql_native_password 更改为 caching_sha2_password。
You can run the below command to resolve the issue.
您可以运行以下命令来解决问题。
sample username / password => student / pass123
示例用户名/密码 => 学生/pass123
ALTER USER 'student'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass123';
Refer the official page for details: MySQL Reference Manual
详情请参考官方页面:MySQL 参考手册
回答by Vishal Boinapalli
May be you are using wrong mysql_connector.
可能是您使用了错误的 mysql_connector。
Use connector of same mysql version
使用相同 mysql 版本的连接器
回答by Greg Charles
I was hitting this error in one Spring Boot app, but not in another. Finally, I found the Spring Boot version in the one not working was 2.0.0.RELEASE and the one that was working was 2.0.1.RELEASE. That led to a difference in the MySQL Connector -- 5.1.45 vs. 5.1.46. I updated the Spring Boot version for the app that was throwing this error at startup and now it works.
我在一个 Spring Boot 应用程序中遇到了这个错误,但在另一个应用程序中没有。最后,我发现 Spring Boot 版本中的一个不工作是 2.0.0.RELEASE,而一个工作是 2.0.1.RELEASE。这导致了 MySQL 连接器的不同——5.1.45 与 5.1.46。我更新了在启动时抛出此错误的应用程序的 Spring Boot 版本,现在它可以工作了。
回答by Turab
You need just to delete your older connector and download new version (mysql-connector-java-5.1.46)
您只需要删除旧的连接器并下载新版本 (mysql-connector-java-5.1.46)
回答by Hyman Ma
I think it is better to update your "mysql-connector" lib package, so database can be still more safe.
我认为最好更新您的“mysql-connector”lib 包,这样数据库就更安全了。
I am using mysql of version 8.0.12. When I updated the mysql-connector-java to version 8.0.11, the problem was gone.
我正在使用 8.0.12 版本的 mysql。当我将 mysql-connector-java 更新到 8.0.11 版本时,问题就消失了。
回答by DataVader
If you can update your connector to a version, which supports the new authentication plugin of MySQL 8, then do that. If that is not an option for some reason, change the default authentication method of your database user to native.
如果您可以将连接器更新到支持 MySQL 8 的新身份验证插件的版本,请执行此操作。如果由于某种原因这不是一个选项,请将数据库用户的默认身份验证方法更改为本机。
回答by user10434384
remove the connect .jar file if you added the multiple version connector jar file only add the connector jar file that match with your sql version.
如果您添加了多版本连接器 jar 文件,则删除连接 .jar 文件,只添加与您的 sql 版本匹配的连接器 jar 文件。
回答by Santosh Gatlewar
I am using mysql 8.0.12 and updating the mysql connector to mysql-connector-java-8.0.12 resolved the issue for me.
我正在使用 mysql 8.0.12 并将 mysql 连接器更新为 mysql-connector-java-8.0.12 为我解决了这个问题。
Hope it helps somebody.
希望它可以帮助某人。
回答by DC-
As Mentioned in above repilies:
正如上面回复中提到的:
Starting with MySQL 8.0.4, the MySQL team changed the default authentication plugin for MySQL server from mysql_native_password to caching_sha2_password.
从 MySQL 8.0.4 开始,MySQL 团队将 MySQL 服务器的默认身份验证插件从 mysql_native_password 更改为 caching_sha2_password。
So there are three ways to resolve this issue:
所以有以下三种方法可以解决这个问题:
1. drop USER 'user_name'@'localhost';
flush privileges;
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_name';
GRANT ALL PRIVILEGES ON * . * TO 'user_name'@'localhost';
ALTER USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY
'user_name';
2. drop USER 'user_name'@'localhost';
flush privileges;
CREATE USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY 'user_name';
GRANT ALL PRIVILEGES ON * . * TO 'user_name'@'localhost'
3. If the user is already created, the use the following command:
ALTER USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY
'user_name';