(1)unity 中mysql 8.0 与mysql connector net 6.10.7较为适配;

 随着MySQL 8.0的发布,MySQL引入了新的默认身份验证插件caching_sha2_password,以提高安全性。然而,这可能导致与旧版客户端或某些编程语言库的不兼容性问题。如果你遇到连接错误,提示与caching_sha2_password有关。考虑更新你的mysql connector net。
经过测试,mysql 8.0 与mysql connector net 6.10.7不存在这个问题;且,mysql 8.0与mysql connector net 7.0.2及以上均不适配

(2)unity连接MySQL数据库时,提示SSL Authentication Error连接失败。

解决方法,在连接字符串中添加SslMode=none;AllowPublicKeyRetrieval=True;即可。

(3)示例 连接语句

private MySqlConnection connection;
    public void Init()
    {
        string sqlString = "server=localhost;user=root;password=123456;database=yuan;SslMode=none;AllowPublicKeyRetrieval=True;";
        connection = new MySqlConnection(sqlString);
        try
        {
            connection.Open();
        }
        catch (System.Exception e)
        {
            Debug.Log("数据库连接失败" + e.Message);
        }
    }
    public void Close()
    {//关闭与服务器数据库的连接;
        connection.Close();
    }

(4)mysql connector 下载相关链接:MySQL :: Download MySQL Connector/NET (Archived Versions)

Logo

一站式 AI 云服务平台

更多推荐