> Markdown version of [MySQL](https://vaadin.com/docs/v23/integrations/databases/mysql). Section index: [llms.txt](https://vaadin.com/docs/v23/integrations/llms.txt)

# Connecting to MySQL

MySQL is a popular relational database from Oracle. You should [install MySQL](https://dev.mysql.com/downloads/) separately before you can connect to it from your Vaadin application (you can also install MySQL as a [Docker container](https://hub.docker.com/_/mysql)).

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.

   `pom.xml`

   ```xml
       <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.

   `application.properties`

   ```properties
   # 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](https://vaadin.com/docs/v23/security/advanced-topics/external-configuration.md) these properties.

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