In a two-tier web application, the data layer is in a separate project. This allows better separation between the presentation layer and the data layer. This way you can reuse the data project in another application that targets the same database.
To access a MySql database you need to add the MySql.Data and MySql.Data.Entity NuGet packages to the data project.
When you develop a two-tier application that targets a MySql database you may get the runtime error
NotSupportedException: Unable to determine the provider name for provider factory of type ‘MySql.Data.MySqlClient.MySqlClientFactory’. Make sure that the ADO.NET provider is installed or registered in the application config.
Even if all database interaction is handled in the data project, and you added the MySql NuGet packages to it, you need to add the MySql.Data and MySql.Data.Entity NuGet packages to the web project too, because the Web.config file contains the connection string that includes the reference to MySql.Data.MySqlClient.
<add name="MY_CONNECTION_NAME" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=MY_DATABASE;uid=MY_USERNAME;password=MY_PASSWORD" />
At the time of writing do not use version 188.8.131.52 of the packages, it causes the error
Exception thrown: ‘System.TypeLoadException’ in mscorlib.dll
An exception of type ‘System.TypeLoadException’ occurred in mscorlib.dll but was not handled in user code
Inheritance security rules violated by type: ‘MySql.Data.MySqlClient.MySqlProviderServices’. Derived types must either match the security accessibility of the base type or be less accessible.
Until a new, corrected version is published, install version 184.108.40.206 of both packages in both projects.
For more information on how to connect to a MySql database from Visual Studio see Connect to a MySQL database from Visual Studio 2017