MySQL + Spring Boot の接続設定をまとめます。
MySQLの設定は下表の通りとします。
| 設定項目 | 値 |
|---|---|
| ホスト名 | localhost |
| データベース名 | sampledb |
| ユーザ名 | user |
| パスワード | pass |
pom.xmlの設定
mysqlに関わる記述をpom.xmlの”dependencies”タグに加えます。
<dependencies>
:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
application.propertiesの設定
mysqlの接続情報を、application.propertiesに加えます。
mysqlの場合、接続URLは
jdbc:mysql://<ホスト名>/<データベース名>
となります。
spring.datasource.url=jdbc:mysql://localhost/sampledb
spring.datasource.username=user
spring.datasource.password=pass
