Please remember that if you are going to use our provided packages for ASP.NET Core Identity you will also need need to include the MySQL package for Identity. For more information, please refer to the article about using Identity for Piranha.
To use MySQL you need to add the NuGet package for running Piranha with Entity Framework Core
and MySQL
.
PM> install-package Piranha.Data.EF.MySQL
PM> install-package Piranha.AspNetCore.Identity.MySQL
After you made sure you have the package reference you need you simply specify that you want to use MySQL and the connection information you want for your database in your Startup.cs
. It is good practice to specify your connection string in your appsettings.json
so you can have different connection strings for different environments, such as,
{
"ConnectionStrings": {
"mydb": "server=<THE-HOST-URL>;port=<THE-PORT>;database=<THE-DATABASE-SCHEME>;uid=<THE-DATABASE-USER>;password=<THE-PASSWORD>"
}
}
Once the configuration is set up it can be used in the ConfigureServices
of the Startup.cs
as shown below.
public class Startup
{
public IConfiguration Configuration { get; private set; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddPiranha(options =>
{
...
var connString = Configuration.GetConnectionString("mydb");
options.UseEF<Piranha.Data.EF.MySql.MySqlDb>(o =>
{
o.UseMySql(connString);
});
// Optional
// First add nuget package Piranha.AspNetCore.Identity.MySQL
options.UseIdentityWithSeed<Piranha.AspNetCore.Identity.MySQL.IdentityMySQLDb>(db => db.UseMySql(connString));
...
});
}
}
That's it! You're now using MySQL with Piranha.
The used MySQL package provides a number of configuration options, such as, character optinos, server versions etc. which are described in detail in the package Wiki.