如何在没有 SSL 的情况下连接到 MySQL 数据库

How to connect to a MySQL Database without SSL

我正在尝试连接到本地 MySQL 数据库。

我有这个连接器:

using(MySqlConnection conn = new MySqlConnection("Database=Studentenverwaltung;Port=3306;Data Source=127.0.0.1;User Id=root;Password=abc123")) 
{
    try 
    {
        conn.Open();
        Console.WriteLine("Opened!");
        conn.Close();
    }
    catch(Exception e) 
    {
        Console.WriteLine("Cannot open Connection");
        Console.WriteLine(e.ToString());
    }
}

但是我得到这个异常:

MySql.Data.MySqlClient.MySqlException (0x80004005): The host 127.0.0.1 does not support SSL connections.

似乎无法连接到数据库,因为数据库不支持SSL。那么有没有办法在没有 SSL 的情况下连接到数据库?

您是否尝试过将连接字符串中的 SslMode 属性 设置为 'none'?

这应该有效:

new MySqlConnection("Database=Studentenverwaltung;Port=3306;Data Source=127.0.0.1;User Id=root;Password=abc123;SslMode=none;")
using MySql.Data.MySqlClient;

private const String SERVER = "1.1.1.1";         // Server IP
private const String DATABASE = "abc";           // Date base name
private const String TABLE = "test";             // Table name
private const String UID = "user";               // Date base username
private const String PASSWORD = "pass";          // Date base password

public static void InitializeDataBase()
{                
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();

builder.Server = SERVER;
builder.UserID = UID;
builder.Password = PASSWORD;
builder.Database = DATABASE;
builder.SslMode = MySqlSslMode.None;
//builder.CertificateFile = @"<Path_To_The_File>\client.pfx";
//builder.CertificatePassword = "<Password_For_The_Cert>";

String connString = builder.ToString();
builder = null;

dbConn = new MySqlConnection(connString);         
}