liveBook · Manning

MySQL

As explained in Quarkus in Action

MySQL is an open-source relational database management system that stores and queries structured data with SQL.

MySQL is the relational database used by the Inventory service. In Quarkus, choosing it does not determine whether Panache uses active record or repository APIs: the database choice and application API are separate. The Inventory service pairs MySQL with the repository pattern. section 7.2

To connect the service and persist its entities:

  • Add the Panache ORM and MySQL JDBC extensions, then configure the datasource in application.properties. section 7.2.1
  • Define a standard JPA entity with an ID, then create an application-scoped class implementing PanacheRepository for that entity. Repository methods can add queries such as a lookup by license plate number. section 7.2.1
Listing 7.12 Properties required for MySQL connection
quarkus.datasource.db-kind=mysql    #1
quarkus.datasource.username=user
quarkus.datasource.password=pass
%prod.quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3306/inventory

# drop and create the database at startup
quarkus.hibernate-orm.database.generation=drop-and-create

The connection properties identify MySQL, supply credentials, and set a production JDBC URL. The shown drop-and-create setting recreates the database schema at startup; it is not a data-preserving setting. section 7.2.1

Deployment changes where the service reaches MySQL. A production URL pointing at localhost is replaced, for the Kubernetes deployment, with a URL using the mysql service name. Applying the manifest creates resources for both the database and Inventory service; the example then checks the pods and forwards the application port. section 11.3.3

Listing 11.12 Changing the location of the MySQL database in Kubernetes
quarkus.kubernetes.env.vars.quarkus-datasource-jdbc-url=
jdbc:mysql://mysql:3306/inventory

This setting supplies the JDBC URL used to reach MySQL from the Kubernetes deployment. section 11.3.3

How Quarkus in Action covers it

How deep it goes
Walks through extensions, datasource properties, a JPA entity, a repository, and a Kubernetes URL change; it does not develop MySQL internals.
Examples
Uses an Inventory service, a Car entity and repository, datasource properties, and a Kubernetes JDBC URL override.
What it assumes
Assumes access to a Quarkus project; leaves Kubernetes cluster setup and kubectl installation outside the deployment walkthrough.
What you can do after
Operate/configure it as an Inventory service datasource locally and through a Kubernetes-specific JDBC URL.
How it connects
Connects MySQL to JDBC, Hibernate ORM with Panache, JPA entities, the repository pattern, and Kubernetes.

Also explained in

Compare how 2 books explain MySQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.