连接MySQL与Unity3D时遇到问题

xpcnnkqh  于 2023-04-19  发布在  Mysql
关注(0)|答案(1)|浏览(441)

我是unity3D的新手。我试图将unity3D与MySQL连接以构建登录和注册模块。unity版本是2021.3.16,MySQL版本是8.0.32。我检查了一些博客并导入MySql.data.dll沿着其他一些dll,如图所示。我写了一个简单的脚本试图测试连接

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MySql.Data.MySqlClient;
using System;
using System.Data;

public class connectMySql : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string connectStr = "server=127.0.0.1;port=3306;database=test;user=root;password=0121;";
        MySqlConnection coon = new MySqlConnection(connectStr);
        try
        {

            coon.Open();
           
            Debug.Log("success");
        }
        catch(Exception e)
        {
            Debug.Log(e.ToString());
        }
       
        coon.Close();
    }

}

控制台报告说

System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Mono.Security.Interface.TlsException: Handshake failed - error code: UNITYTLS_INTERNAL_ERROR, verify result: 4294936704
  at Mono.Unity.Debug.CheckAndThrow (Mono.Unity.UnityTls+unitytls_errorstate errorState, Mono.Unity.UnityTls+unitytls_x509verify_result verifyResult, System.String context, Mono.Security.Interface.AlertDescription defaultAlert) [0x00036] in <cb1c94a571d140989f59bc38dfed683a>:0 
  at Mono.Unity.UnityTlsContext.ProcessHandshake () [0x00082] in <cb1c94a571d140989f59bc38dfed683a>:0 
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus status, System.Boolean renegotiate) [0x000da] in <cb1c94a571d140989f59bc38dfed683a>:0 
  at (wrapper remoting-invoke-with-check) Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncOperationStatus,bool)
  at Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncOperationStatus status) [0x00006] in <cb1c94a571d140989f59bc38dfed683a>:0 
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (System.Threading.CancellationToken cancellationToken) [0x000fc] in <cb1c94a571d140989f59bc38dfed683a>:0 
   --- End of inner exception stack trace ---
  at Mono.Net.Security.MobileAuthenticatedStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x0004b] in <cb1c94a571d140989f59bc38dfed683a>:0 
  at (wrapper remoting-invoke-with-check) Mono.Net.Security.MobileAuthenticatedStream.AuthenticateAsClient(string,System.Security.Cryptography.X509Certificates.X509CertificateCollection,System.Security.Authentication.SslProtocols,bool)
  at System.Net.Security.SslStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x00006] in <cb1c94a571d140989f59bc38dfed683a>:0 
  at MySql.Data.MySqlClient.NativeDriver.StartSSL () [0x00035] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.NativeDriver.Open () [0x002ce] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.Driver.Open () [0x0000b] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x0004e] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection () [0x00000] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection () [0x0008a] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x0003f] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in <0004ab8b375b422f9000ac25a68089d9>:0 
  at connectMySql.Start () [0x0000b] in D:\unity\project\test\Assets\connectMySql.cs:18

我该怎么做才能解决这个问题呢?非常感谢
我搜索并没有找到有用的提示对这个问题.似乎没有人面对这个问题之前,这是非常奇怪的.我想这可能是因为Unity版本,MySQL版本和.Net版本不匹配.我试图使用不同版本的Mysql. data. dll,但它不起作用

yduiuuwa

yduiuuwa1#

我认为你的:

string connectStr = "server=127.0.0.1;port=3306;database=test;user=root;password=0121;";

不应该有“;”,所以应该是这样的:

string connectStr = "server=127.0.0.1;port=3306;database=test;user=root;password=0121";

相关问题