C# 連mysql時,出現mysql_native_password

29 篇文章 0 订阅

DB名稱異常

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '**IP地址**' for user '**有戶名**' using method 'mysql_native_password' failed with message: Access denied for user 'lrmis'@'%' to database 'maildb1' ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'lrmis'@'%' to database 'maildb1'

 

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '**IP地址**' for user '**有戶名**' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.

此異常偶爾出現,網上介紹連接字符串加上sslmode=none; 待觀察驗證

 

正常情況下是連接字符串不對時,每次都會出現此異常 ,寫不正確的db名稱

 return string.Concat(new string[]
			{
				"Database='",
				this._DBName,
				"';Data Source='",
				this._ServerName,
				"';Persist Security Info=True;min pool size=20;max pool size=10240;Connection Timeout = 15;CharSet=UTF8mb4;Pooling=true;User Id='",
				this._LoginUser,
				"';Password='",
				this._PassWord,
				"';charset='utf8mb4';pooling=true;sslmode=none;"
			});
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在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服务器已正确配置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值