環境
windows7 64bit
mysql 5.6.43
spring-boot 2.3.2
参照資料:Spring公式GUIDES
1. Accessing data with MySQL用ソースを取得
git clone https://github.com/spring-guides/gs-accessing-data-mysql.git
2. DB初期化
cd into gs-accessing-data-mysql/initial
公式GUIDESはlinux用のため、下記コマンドそのまま使用すると※1エラーが発生
create user 'springuser'@'%' identified by 'ThePassword';
※1java.sql.SQLSyntaxErrorException: Access denied for user 'springuser2'@'localhost' to database 'db_example'
windows場合、下記のように修正必要
mysql> create database db_example; -- Creates the new database
mysql> create user 'springuser'@'localhost' identified by 'ThePassword'; -- Creates the user
mysql> grant all on db_example.* to 'springuser'@'localhost'; -- Gives all privileges to the new user on the newly created database
3. springboot起動
mvn spring-boot:run
下記※2エラー発生
※2java.sql.SQLException: The server time zone value '???? (?W????)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
application.properties下記対策必要
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example?serverTimezone=JST&useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=springuser2
spring.datasource.password=ThePassword