Documentation

Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Connecting to MySQL

Use MySQL in your Vaadin application.

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 by following the steps below:

  1. Add the mysql-connector-java dependency to the pom.xml file.

        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <scope>runtime</scope>
        </dependency>
  2. Add MySQL configuration properties to the src/main/resources/application.properties file. You have to replace HOST, PORT, DB_NAME, USERNAME, PASSWORD with corresponding parameters from your MySQL instance.

    # 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
Caution
Avoid storing sensitive information in the project’s properties file.

It’s bad practice to store database URI, username, and passwords in the application.properties file. You should consider externalizing these properties.

694CE8F4-DF75-41CE-8C30-5C332BA0C5E3