Połączenie z Mysql [WinForms]

Na początku potrzebujemy Connector dla platformy .NET [Mono & .NET]

https://dev.mysql.com/downloads/connector/net/

Pobrany plik musimy rozpakować do folderu z projektem

Rejestrujemy bibliotekę dll w mono ( komenda linux)

sudo gacutil -i MySql.Data.dll

Kod programu do połączenia z bazą danych mysql

using System;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
 
public class Form1 : Form
{
    static public void Main ()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        Application.Run (new Form1 ());
    }
        public Button button1;
        MySql.Data.MySqlClient.MySqlConnection conn;
         string myConnectionString;

    public Form1 ()
    {
    button1 = new Button();
    button1.Size = new Size(140, 40);
    button1.Location = new Point(30, 30);
    button1.Text = "Click me";
    this.Controls.Add(button1);
    button1.Text = "Click here to save changes";
    button1.Font = new Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Point);
    button1.Click += new EventHandler(button1_Click);

    myConnectionString = "server=127.0.0.1;uid=root;pwd=12345;database=test";
 
     }

    private void button1_Click(object sender, EventArgs e)
    {
   try
    {
    conn = new MySql.Data.MySqlClient.MySqlConnection();
    conn.ConnectionString = myConnectionString;
    conn.Open();
    }
    catch (MySql.Data.MySqlClient.MySqlException ex)
    {
    MessageBox.Show(ex.Message);
    }
    }
 


   
}

Kompilacja projektu wraz z zależnościami

mcs win.cs -r:System.Windows.Forms.dll -r:System.Drawing.dll -r:MySql.Data.dll -r:System.dll -r:System.Data.dll