Documentation

Documentation versions (currently viewingVaadin 23)

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 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 will 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