执行MySQL安装程序,安装MySQL For Visual Studio和Connector/NET
执行命令:
Install-Package EntityFramework Install-Package MySql.Data -Version 6.9.8 Install-Package MySql.Data.Entity -Version 6.9.8 |
MySQL连接语句:
<connectionStrings>
<add name="FgwContext" connectionString="server=192.168.7.205;user id=fgw;password=fgw3edc#;persistsecurityinfo=True;database=fgwpro" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
修改Config:
<connectionStrings>
<add name="Default" connectionString="data source=192.168.7.205;user id=fgw;password=fgw3edc#;database=fgwpro;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="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" />
</DbProviderFactories>
</system.data>
错误记录:
No MigrationSqlGenerator found for provider 'MySql.Data.MySqlClient'. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators. 解决方案: 需要在Context指定Mysql的配置文件。 [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] 中文乱码问题 使用语句 show variables like 'character%'; 来查看当前数据库的相关编码集。
[mysql] default-character-set=utf8 [mysqld] character-set-server=utf8 重启MySQL服务即可。 |