Skip to content

MySQL DB 연동 #2

@dhgkdud12

Description

@dhgkdud12

MySQL Workbench 이용

사용자 계정 생성
create user '아이디'@'%' identified by '비밀번호';

사용자 권한 부여
GRANT ALL PRIVILEGES ON . TO '아이디'@'%';

image
생성한 계정으로 Connection을 새로 생성해야함.

dogamdogam 데이터베이스 생성
CREATE DATABASE dogamdogam CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

데이터베이스 사용
use dogamdogam;

POST 테이블 생성
create table dogamdogam.post (
id integer not null auto_increment,
category varchar(255) not null,
create_date datetime(6),
description varchar(255) not null,
image varchar(1000),
num_ofpeople integer not null,
place varchar(255) not null,
price integer not null,
title varchar(255) not null,
primary key (id)
);

REPLY 테이블 생성
create table dogamdogam.reply (
id integer not null auto_increment,
content varchar(255) not null,
create_date datetime(6),
image varchar(255),
post_id integer,
primary key (id)
);

USER_INFO 테이블 생성
create table dogamdogam.user_info (
id integer not null auto_increment,
user_email varchar(255),
user_id integer,
user_image varchar(255),
user_nickname varchar(255),
primary key (id)
);

테이블 정보 조회
select * from dogamdogam.post;
select * from dogamdogam.reply;

Intellij
application.properties 파일에서 MySQL 연동

#MySQL
spring.datasource.url=jdbc:mysql://localhost:3306/dogamdogam?serverTimezone=Asia/Seoul&sessionVariables=sql_mode='NO_ENGINE_SUBSTITUTION'&jdbcCompliantTruncation=false
spring.datasource.username=아이디
spring.datasource.password=비밀번호
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions