Connecting to MySQL
MySQL is a popular relational database from Oracle. You should install MySQL separately before you can connect to it from your Vaadin application (you can also install MySQL as a Docker container).
For an existing Vaadin project, you can connect to MySQL with a few steps. First, add the mysql-connector-java
dependency to the pom.xml
file like so:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Next, add MySQL configuration properties to the src/main/resources/application.properties
file.
# MySQL Configuration
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://HOST:PORT/DB_NAME
spring.datasource.username=USERNAME
spring.datasource.password=PASSWORD
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
You have to replace HOST
, PORT
, DB_NAME
, USERNAME
, PASSWORD
with corresponding parameters from your MySQL instance.
Caution
|
Don’t Store Sensitive Information in a Project’s Properties File
It’s bad practice to store database URI, username, and passwords in the |
694CE8F4-DF75-41CE-8C30-5C332BA0C5E3