C#连接mysql数据库
首先下载mysql的DLL
https://files.cnblogs.com/files/wlphp/MySql.Data.zip
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql; using MySql.Data; using MySql.Data.MySqlClient; namespace fast { public class DB { public void index() { String connetStr = "server=118.25.108.136;port=3306;user=admin;password=123456; database=zhihu;"; // server=127.0.0.1/localhost 代表本机,端口号port默认是3306可以不写 MySqlConnection conn = new MySqlConnection(connetStr); try { conn.Open();//打开通道,建立连接,可能出现异常,使用try catch语句 Console.WriteLine("已经建立连接"); //在这里使用代码对数据库进行增删查改 } catch (Exception ex) { Console.Write(ex); } } } }