๐ŸŒธ Getting Started With Database (feat. mySQL, Spring)

Sungju Kimยท2024๋…„ 8์›” 13์ผ

Sparta_Coding_Camp_TIL

๋ชฉ๋ก ๋ณด๊ธฐ
14/53

Setting up SQL in Spring

1. Create a database in the terminal

Input the following commands in order in the terminal.

cd /usr/local/mysql/bin
./mysql -u root -p

How to check current data bases

show databases;

How to add new database

create database new_db_name;

How to delete/drop database

drop database db_to_remove;

2. Setting up SQL in Spring

Add the following in 'applications.properties'

spring.datasource.url=jdbc:mysql://localhost:3306/memo
spring.datasource.username=root
spring.datasource.password=Sungju0909!
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

Add the SQL specific dependencies in 'build.gradle'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    
    // MySQL - add these dependencies
    implementation 'mysql:mysql-connector-java:8.0.28'
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
}

Side note: how to set up Git Configuration

Type the following commands with your user name and email in the terminal or the CMD.

git config --global user.name "Robbie"
git config --global user.email "Robbie@email.com"
profile
Fully โœจcommittedโœจ developer, always eager to learn!

0๊ฐœ์˜ ๋Œ“๊ธ€