项目连接mysql时报caching_sha2_password错误

错误信息如下:

java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:505)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:479)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:489)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:78)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1606)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)
	at com.alibaba.druid.filter.F
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
在Unity中连接MySQL数据库时,如果出现"caching_sha2_password"的提示,这是因为MySQL 8.0版本引入了新的身份验证插件"caching_sha2_password",而Unity默认使用的是旧的身份验证插件"mysql_native_password"。为了解决这个问题,你可以按照以下步骤进行操作: 1. 在Unity中安装MySQL Connector/NET。你可以从MySQL官方网站下载并安装最新版本的Connector/NET。 2. 在Unity项目中创建一个C#脚本,用于连接MySQL数据库。 3. 在脚本中使用以下代码进行数据库连接: ```csharp using System.Data; using MySql.Data.MySqlClient; public class DatabaseConnector : MonoBehaviour { private MySqlConnection connection; private string server = "your_server_address"; private string database = "your_database_name"; private string uid = "your_username"; private string password = "your_password"; void Start() { string connectionString = "Server=" + server + ";Database=" + database + ";Uid=" + uid + ";Pwd=" + password + ";SslMode=none;"; connection = new MySqlConnection(connectionString); try { connection.Open(); Debug.Log("Connected to MySQL database!"); } catch (MySqlException ex) { Debug.LogError("Failed to connect to MySQL database: " + ex.Message); } } void OnApplicationQuit() { if (connection != null && connection.State != ConnectionState.Closed) { connection.Close(); Debug.Log("Disconnected from MySQL database!"); } } } ``` 请确保将"your_server_address"替换为你的MySQL服务器地址,"your_database_name"替换为你的数据库名称,"your_username"替换为你的数据库用户名,"your_password"替换为你的数据库密码。 这样,你就可以在Unity中连接MySQL数据库了。如果仍然遇到"caching_sha2_password"的提示,请确保你使用的是最新版本的Connector/NET,并且MySQL服务器已正确配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值