스프링 부트 MySQL8 연동 Intellij
1. MySQL 커넥터 의존성을 추가한다.
- MySQL에 접속할 수 있는 커넥터 의존성을 추가해야 한다.
- datasource에 구현체이다.
1
2
3
4
5
|
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
|
cs |
1
2
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'mysql:mysql-connector-java'
|
cs |
Gradle 기반
2. application.properties 설정 파일에 다음과 같이 DataSource를 설정해준다.
1
2
3
4
5
|
spring.datasource.url=jdbc:mysql://localhost:3306/example?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
spring.datasource.username=temp
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
cs |
3. Spring Data JPA를 사용한다면 다음의 설정을 추가하자.
1
2
3
4
5
|
# MySQL 을 사용할 것.
spring.jpa.database=mysql
# MySQL 상세 지정
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
|
cs |
4. MYSQL에 유저 권한 설정을 해주자.
이때 database 이름을 example로 하고 user에 이름을 'temp' 패스워드를 pass로 해보자
1) mysql> CREATE USER 'temp'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass';
2) mysql> GRANT ALL PRIVILEGES ON example.* TO'temp'@'localhost';
3) mysql> create database example
( 자세한 정보 : https://stackoverflow.com/questions/50177216/how-to-grant-all-privileges-to-root-user-in-mysql-8-0 )
5. Intellij 의 얼티밋을 쓴다면
6. 만약 set timeZone 에러가 뜬다면?
https://dev.mysql.com/downloads/timezones.html
MySQL :: Time zone description tables
Please don't use this package if your system includes zoneinfo files (e.g. Linux, FreeBSD, Sun Solaris) Please generate the mysql.time_zone* tables from those files using the mysql_tzinfo_to_sql utility instead! (Otherwise you may cause a difference in dat
dev.mysql.com
timezone_2020a_leaps.sql.zip을 받는다. (Window 기준)
다음과 같이 경로에 있는 leaps.sql을 source로 실행한다.
정상적으로 실행이 됬다면 이제 setTimeZone이 Asia/Seoul로 나오게 된다.
이제 정상적으로 Connection 되는 것을 알 수 있다.
다음과 같은 방법으로도 간단히 가능하다 )