Getting started with ASP.NET Core and MySQL Connector/NET

This tutorial shows how to read information from MySQL Sakila database in an ASP.NET Core application using Connector/NET Core to explore the possibility to run this application on any .NET Core supported environment as Windows, Linux, and Mac.


Windows and Visual Studio 2015

The first step is to create an ASP.NET Core Web Application (.NET Core) type project and name it MvcSakilaCore

Note: the project name should not contain spaces



Select Web Application template and No Authentication:


The new project will be created:


Press F5 to run the application:


Stop the running application to add some code.

Creating the data model

Create a new folder named “Models” where it will store the database access:


Installing MySQL Connector/NET Core package

In order to use MySQL Connector/NET it’s required to add its nuget package.

In Solution Explorer, right-click MvcSakilaCore project > Manage NuGet Packages…
In the NuGet dialog, Browse “MySql.Data” package using version 6.10.0 or above:


Adding the connection string

Add your connection string in the appsettings.json file:


Adding data model classes

For this example a Film class will be used. It contains the database fields as properties we want to show in our application.

Add a new class named “Film” inside Models folder:

Create a new SakilaContext class that will contains the connections and Sakila database entities:

In order to be able to use our SakilaContext it’s required to register the instance as a service in our application. To do this add the code line in the Startup.cs file:


Adding Film Controller

In Solution Explorer, right-click Controllers > Add > New Item… > MVC Controller Class
Name the controller FilmsController:



Change the FilmsController code to this:

Creating the Films View

Start creating the Films folder under Views:

In Solution Explorer, right click Views > Films > Add > New Item… > ASP.NET > MVC View Page


Add the following code into the new Index.cshtml view file:

Before run the application, add the Films path to the running url.

In Solution Explorer, right click MvcSakilaCore > Properties > Debug > Launch URL > Films:


Run the application (press F5) and the Films list should be displayed:



MySQL Connector/NET 6.7.8, 6.8.6, and 6.9.7 have been released

Dear MySQL users,

MySQL Connector/Net 6.7.8, 6.8.6, and 6.9.7 are maintenance releases for the series of the .NET driver for MySQL. They can be used for production environments.

They are appropriate for use with MySQL server versions 5.5-5.7.

They are now available in source and binary form from
(note that not all mirror sites may be up to date at this point-if you can’t find this version on some mirror, please try again later or choose another download site.)

Changes in MySQL Connector/Net 6.8.8

  • Connections to MySQL server 5.7 now default to using SSL.

Changes in MySQL Connector/Net 6.8.6

  • Connections to MySQL server 5.7 now default to using SSL.

Changes in MySQL Connector/Net 6.9.7

  • The selection of a master or slave now takes into account
    both the status and mode, when before it only used the
    mode. Ignoring the status was problematic as, for
    example, an unreachable server’s status is marked as
    FAULTY while the mode does not change. (Bug #21203824)
  • Using MySqlConnection.Open() with Connector/Net 6.9.6
    would fail and raise the error “Unable to connect to
    Fabric server”. (Bug #20983968)
  • Connections to MySQL server 5.7 now default to using SSL.

The documentation is available at:

Nuget packages are available at:

Enjoy and thanks for the support!

On behalf of the MySQL Connector/NET Team.