1.VS2010环境下貌似不能直接连接该数据库,所以请先下载安装:http://mysql.ntu.edu.tw/Downloads/Connector-Net/mysql-connector-net-6.4.4.msi(mysql-connector-net-6.4.4.msi)

2.接下来的操作和Oracle数据库就完全一样了:

1)首先导入控件命名:(如果报错,请先添加引用)

using MySql.Data.MySqlClient;

2)连接操作:

public DB(){
    connection = "Database=mysql;Data Source=127.0.0.1;User Id=lqm;Password=lqm;pooling=false;CharSet=utf8;port=3306";//mysql是数据库名字,id和password是用户名和密码
    conn = new MySqlConnection(connection);  
}

3)打开链接:

conn.Open();

4)关闭操作:

conn.Close();

5)给一个查询示例:

String sql = "select pswd" + " from account  where id = '" + account + "' and user = 0";
 MySqlCommand command = conn.CreateCommand();
 command.CommandText = sql;
 MySqlDataReader reader = command.ExecuteReader();
 if (reader.Read())
 {
     //如果有数据
     String db_pwd = reader.GetString(0);
 }

大体上和Oracle下完全一样,只是把MyOracleCommand换成MySqlCommand;