1、首先需要下载安装.Net的Mysql驱动
下载地址如下:http://dev.mysql.com/downloads/connector/net/
2、配置Web.Config
EF6:
配置链接字符串
<connectionStrings> <add name="sqldata" connectionString="server=地址;Character Set=utf8;User Id=用户名;password=密码;Persist Security Info=True;database=数据库名称" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
配置驱动
<system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient"></remove><!--预防Machine.config中已经配置了MySql.Data.MySqlClient--> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>
配置EF6的驱动
<entityFramework> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> </providers></entityFramework>
EF4.1:
配置链接字符串
<connectionStrings> <add name="sqldata" connectionString="server=地址;Character Set=utf8;User Id=用户名;password=密码;Persist Security Info=True;database=数据库名称" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
配置驱动
<system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient"></remove><!--预防Machine.config中已经配置了MySql.Data.MySqlClient--> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>
配置完这些就可以使用Mysql了 !
时间: 2024-10-16 13:45:17