Jakeuj's Notes master Help

ABP.IO 同時使用 MSSQL 與 MySQL

筆記下關於 Option 'trusted_connection' not supported. 的坑

例外

MYSQL Option 'trusted_connection' not supported.

結論

總之改用下面這段就可以了

Server=127.0.0.1;Port=3306;Uid=root;Pwd=;Database=Csharp_Hotel_DB

於原本比較一下應該是不能有空格?

Server=127.0.0.1; Database=Csharp_Hotel_DB; Port=3306; Uid=root; Pwd=

補充

  1. 基本參照官方多資料庫的說明文件 Entity Framework Core

  2. 需額外安裝套件 Volo.Abp.EntityFrameworkCore.MySQL

  3. DbContextFactory 裡面改用 UseMySql 並提供 MySql 版本參數 (Select Version();) UseMySql(configuration.GetConnectionString("Hotel"), ServerVersion.Parse("8.0.33-0ubuntu0.22.04.2"));

  4. EntityFrameworkCoreModule 裡面加上 options.Configure<HotelDbContext>(o => { o.UseMySQL(); });

DbContextFactory

public HotelDbContext CreateDbContext(string[] args) { var configuration = BuildConfiguration(); var builder = new DbContextOptionsBuilder<HotelDbContext>() .UseMySql(configuration.GetConnectionString("Hotel"), ServerVersion.Parse("8.0.33-0ubuntu0.22.04.2")); return new HotelDbContext(builder.Options); }

EntityFrameworkCoreModule

context.Services.AddAbpDbContext<HotelDbContext>(options => { options.AddDefaultRepositories(includeAllEntities: true); }); Configure<AbpDbContextOptions>(options => { /* The main point to change your DBMS. * See also TestMigrationsDbContextFactory for EF Core tooling. */ options.UseSqlServer(); // for MySql DbContext options.Configure<HotelDbContext>(o => { o.UseMySQL(); }); });

參照

Entity Framework Core MySQL | Documentation Center | ABP.IO

How To Check MySQL Version: 5 Easy Commands {Ubuntu, Linux} (phoenixnap.com)

ABP.IO WEB應用程式框架 使用多個資料庫 | 御用小本本 - 點部落 (dotblogs.com.tw)

Jakeuj

PS5

  • Entity Framework

  • MSSQL

  • MySql

  • 回首頁

本文章從點部落遷移至 Writerside

13 October 2025