今天复习了下c#连接mysql 记录下来方便自己也方便别人!
使用vs2010连接mysql 数据库,
1.装连接驱动,使用Connector/Net 连接驱动!下载地址:http://dev.mysql.com/downloads/connector/net/, 安装完之后,在项目中添加引用 Mysql.Data.dll;
2.配置连接串:
在web.config 中
1 <configuration 2 <connectionStrings> 3 <add name="MysqlConnection" connectionString="server=localhost;user id=root;password=123456;database=test1;" /> 4 </connectionStrings> 5 </configuration
后台代码中:
1 string sqlstring = System.Configuration.ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; 2 3 MySqlConnection myconn=new MySqlConnection(sqlstring); 4 myconn.Open();
到此为止,已经连接了mysql的数据库了~