一、在Startup.cs中注册
var conn = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<MyContext>(options => options.UseMySQL(conn));
二、在MyDBContext.cs中重写OnConfiguring方法
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseMySql("server=localhost;userid=root;pwd=xxx;port=3306;database=world;");