참고/Mac

[mac] h2 데이터베이스

민발자 2024. 3. 12. 16:03
728x90

 

H2 Database

자바로 작성된 관계형 데이터베이스 관리 시스템으로 로컬환경에서 테스트나 개발을 위해 간편하게 사용

 

특징

인 메모리 DB로 메모리에 데이터가 저장되고 애플리케이션이 종료되면 모든 메모리는 삭제된다.

별도의 설치가 필요 없고 작은 용량과 매우 가볍고 빠르기 때문에 개발 단계나 테스트 코드에서 자주 사용된다.

RDBMS보단 안정성이나 성능에서는 떨어지기 때문에 대규모 프로젝트에서는 적합하지 않다.

 

다운로드

https://h2database.com/html/main.html

 

H2 Database Engine

H2 Database Engine Welcome to H2, the Java SQL database. The main features of H2 are: Very fast, open source, JDBC API Embedded and server modes; in-memory databases Browser based Console application Small footprint: around 2.5 MB jar file size     Supp

h2database.com

All Platforms 다운로드

 

실행

압축해제

압축을 풀어주고 원하는 폴더에 이동

// 폴더로 이동
cd Documents/h2/bin

// 실행
./h2.sh

//permission Error 발생시 권한 부여
chmod 755 h2.sh

 

 

사용법

데이터베이스 생성

h2 콘솔창

jdbc:h2:~/testDB

 

사용자/사용자명 폴더에 생성

터미널에서 실행 해주면 콘솔창이 뜨고 연결해 주면 데이터베이스가 생성된다.

 

데이터베이스 접속

jdbc:h2:tcp://localhost/~/testDB

데이터베이스 생성 이후엔 localhost로 접속!

 

 

 

JDBC 연결

build.gradle 라이브러리 추가

implementation 'org.springframework.boot:spring-boot-starter-jdbc'
runtimeOnly 'com.h2database:h2'

 

properties 연결 설정 추가

spring.datasource.url=jdbc:h2:tcp://localhost/~/testDB
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa

 

728x90