先在网上找到Mysql.Data.dll组件,
文件下载地址为http://dev.mysql.com/downloads/connector/net/6.6.html#downloads ,下载平台选择.Net&Mono,下载ZIP免安装版
然后再项目中引用,之后操作你的数据库,我这里以test为例
string constr = "server=localhost;User Id=root;password=root;Database=test"; MySqlConnection mycon = new MySqlConnection(constr); try { mycon.Open(); MySqlCommand mycmd = new MySqlCommand("insert into ksk_member(nickname) values(‘小王‘)", mycon); if (mycmd.ExecuteNonQuery() > 0) { Console.WriteLine("数据插入成功!"); } Console.ReadLine(); } catch (Exception ex) { return false; } finally { mycon.Close(); }