15. Appendices
15.1. DBMS and MySQL with Laragon
In 2008, the course appendices described the installation of SQL Server 2005 Express and MySQL 5, their administration tools (MySQL GUI Tools) and their ODBC drivers, with about thirty screenshots. Chapters 10 and 11 of this document use only MySQL 8, and the easiest way to install it on Windows is to install Laragon, a portable development environment that includes, among other things, MySQL, the graphical client HeidiSQL, a configured terminal, Apache, and PHP. The author also uses it for his PHP courses.
15.1.1. Installation
Laragon can be downloaded from https://laragon.org. The installation is standard; you can keep the suggested installation folder ([C:\laragon]). Laragon provides MySQL 8 (the exact version depends on the Laragon version), with a password-less administrator account ([root]) and a server listening on port 3306 on the local machine. This is the configuration assumed by the examples in this document, where the connection strings are in the form:
If MySQL was installed differently, with a password for [root], you must replace it with [Password=] in the connection strings of the examples ([appsettings.json] files or constants at the top of the programs).
For a system without Laragon, you can also install MySQL Community Server from https://dev.mysql.com/downloads/mysql/, or its open-source derivative, MariaDB. However, the examples have only been tested with MySQL 8: the scripts in Chapter 10 use a collation specific to MySQL 8 ([utf8mb4_0900_ai_ci]), and the examples in Chapter 11 pass a MySQL server version ([MySqlServerVersion]) to Pomelo; with MariaDB, these two points would need to be adjusted.
15.1.2. Starting and Stopping MySQL
The Laragon main window includes a “Start All” button that starts the servers (Apache and MySQL) and a “Stop” button that stops them. Unlike the MySQL 5 installation described in 2008, MySQL is not a Windows service that runs at system startup: it only runs when started from Laragon, which prevents it from consuming resources when not in use. The Laragon menu (right-click in the window) also allows you to start only MySQL and to select its version.
When MySQL is not running, the programs in Chapters 10 and 11 fail with an exception indicating that no connection could be established (“Unable to connect to any of the specified MySQL hosts”): This is the first thing to check if an error occurs.
15.1.3. The Command-Line Client
The Terminal button in Laragon opens a terminal where Laragon commands are available, including the MySQL command-line client [mysql]. To connect to the server, use:
then enter SQL commands ending with a semicolon ([show databases;], [use dbarticles;], [select * from articles;]) and [exit] to exit. The client can also run an SQL script, which Chapter 10 does to create its databases:
The scripts completely recreate their database each time they are run: you can rerun them to restore the data to its initial state after testing.
15.1.4. The HeidiSQL graphical client
The Laragon Database button launches the graphical client HeidiSQL, which replaces the 2008 MySQL GUI Tools (now deprecated). Upon first launch, HeidiSQL offers a connection session that is already configured for the Laragon MySQL server (host [127.0.0.1], user [root], blank password, port 3306); simply open it. You’ll see:
- on the left, the tree view of the server’s databases and their tables;
- On the right, tabs that display a table's structure, its data (which can be edited directly), and a field for entering SQL queries (the "Query" tab), which are executed by [F9].
To create a database using a script from Chapter 10, open the script (via the “File” menu, using the “Load SQL file” command) in a query tab, then execute it ([F9]). You can also create a database, a user, and user permissions using the menus in HeidiSQL (right-click on the connection / “Create New” / "Database"; "Tools" menu / "User Manager"), but the SQL scripts have the advantage of being reproducible and able to be rerun.
15.1.5. The Databases in This Document
Chapters 10 and 11 use the following databases, all located on the local MySQL server:
Database | Chapter | Creation |
[dbarticles] | 10 | Script [10-adonet/sql/dbarticles.sql]: Table [articles] from the ADO.NET examples |
[dbtaxes] | 10 | script [10-adonet/sql/dbtaxes.sql]: the [brackets] table from version 6 of the [Tax] application and the [admtaxes] user |
[efarticles], [efshop], [efclients] | 11 | created by the programs themselves ([EnsureCreated]) or by migrations from EF Core ([dotnet ef database update]) |
[eftaxes] | 11 | created by the migration of the project from version 7 of the application [Tax] |
Once testing is complete, a database can be deleted using the SQL command [drop database name;], in the [mysql] client, or in HeidiSQL.
15.2. The NuGet packages used
The following table summarizes the NuGet libraries used by the examples, along with the versions with which the examples were tested. They are downloaded automatically by the [dotnet] command during the first compilation (so Internet access is required at that time).
Package | Version | Chapters |
[Microsoft.Extensions.DependencyInjection] | 10.0.12 | 6, 10, 11, 12 |
[Microsoft.Extensions.Configuration.Json] | 10.0.12 | 6, 10, 11, 12 |
[MSTest] | 4.0.2 | 6, 10 |
[MySqlConnector] | 2.4.0 | 10 |
[Microsoft.EntityFrameworkCore] | 9.0.0 | 11 |
[Microsoft.EntityFrameworkCore.Relational] | 9.0.0 | 11 |
[Microsoft.EntityFrameworkCore.Design] | 9.0.0 | 11 |
[Pomelo.EntityFrameworkCore.MySql] | 9.0.0 | 11 |
[Microsoft.Extensions.Http] | 10.0.12 | 13 |
The EF Core migration tool is installed once and for all using the [dotnet tool install --global dotnet-ef --version 9.0.0] command (Chapter 11). ASP.NET Core (Chapters 12 and 13) is part of the SDK and does not require any packages.