[Naem] 개발 시작 - 프로젝트 생성 및 db 연결
프로젝트 생성
Spring Initializr를 이용했으며, 설정은 아래와 같이 했다.

build.gradle
plugins {
	id 'org.springframework.boot' version '2.6.9'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}
group = 'naem'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}
repositories {
	mavenCentral()
}
dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-devtools'
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'mysql:mysql-connector-java'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
	useJUnitPlatform()
}
db 연결
application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/naem?serverTimezone=UTC&characterEncoding=UTF-8
    username: testuser
    password: 1234
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        format_sql: true
logging.level:
  org.hibernate.SQL: debug
#  org.hibernate.type: trace
이대로 애플리케이션을 실행하면 아래 에러가 발생한다!

추후에 db 연결 정보는 docker-compose.yml에 직접 등록한다.
이 글을 참고하자!
테이블 생성 및 권한 부여
1. MySQL 워크벤치 - MySQL Connections 추가

2. 터미널 - mysql 접속
mysql -u root -p
패스워드를 입력하면 mysql에 접속할 수 있다.
3. 아래 sql문 실행
create user 'username'@'%' identified by 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';
CREATE DATABASE blog CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
use blog;
show variables like 'c%';
예를들면, 아래처럼 입력하면 된다. (소문자로 입력해도 된다.)
create user 'testuser'@'%' identified by '1234';
GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'%';
CREATE DATABASE blog CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
use blog;
show variables like 'c%';
4. 완료!
- MySQL 워크벤치에 들어가서 1번에서 만들어둔 Connection에 설정한 이름과 비밀번호로 접속해보면, 성공적으로 접속되는 것을 확인할 수 있다.
 - 인텔리제이에서 애플리케이션을 실행해보면 잘 실행되는 것을 확인할 수 있다.
 
Ref.
https://chanho0912.tistory.com/18
💛 개인 공부 기록용 블로그입니다. 👻