0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

windowsのmysqlでspringboot実装エラー対策

Posted at

環境

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?