首页 > 解决方案 > 使用 raspbian 在 C# 应用程序中连接到 MariaDB

问题描述

我一直在尝试在我的 pi3 上运行一个使用 mysql (mariadb) 并像这样连接的服务器:

mySQLSettings.connection = new MySqlConnection("SERVER=localhost;DATABASE=servertest;UID=root;PASSWORD=;");
mySQLSettings.connection.Open();

当我使用 XAMPP 时,它在 Windows 上运行良好。但是,当我在我的 pi 上运行该应用程序时,它会抛出这个:

Could not connect to MySQL: MySql.Data.MySqlClient.MySqlException (0x80004005): Client does not support authentication protocol requested by server; consider upgrading MariaDB client
  at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x0006e] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.NativeDriver.AuthenticateNew (System.Boolean reset) [0x000ed] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.Boolean reset) [0x00040] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.NativeDriver.Open () [0x00344] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.Driver.Open () [0x0000c] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00058] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection () [0x0001e] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection () [0x000b5] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00051] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x00021] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0013e] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
  at GameServer.MySQL.ConnectToMySQLServer () [0x00000] in <16fb46a8a2244c9e90373e583102cae7>:0

MariaDB 的版本是 10.3.22,我使用的是 MySql.Data-6.4 dll

我错过了一些简单的东西吗?

提前致谢!

标签: c#mysqlmariadbraspberry-pi3raspbian

解决方案


您使用的是相当旧的 MySql.Data.dll 版本,它可能不支持您的服务器正在使用的身份验证方案。

在这种情况下,我建议切换到MySqlConnector,它对 MariaDB 有更好的客户端支持,包括它的auth_gss_clientauth_ed25519身份验证方案(后者在单独的包中)。


推荐阅读