java

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(2) - MySQL ํ•œ๊ธ€ ์…‹ํŒ…ํ•˜๊ธฐ, ์œ ์ € ์ƒ์„ฑ

dev_summer 2020. 11. 9. 15:25

 

 

 

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์„œ๋ฒ„๋ฅผ urf-8๋กœ ๋ณ€๊ฒฝํ•ด์•ผํ•œ๋‹ค. ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์œˆ๋„์šฐ์™€ ๋ฆฌ๋ˆ…์Šค๊ฐ€ ๋‹ค๋ฅด๋‹ค.

 

๊ฒฝ๋กœ : C:\ProgramData\MySQL\MySQL Server 5.7

 

 

1. ์œˆ๋„์šฐ

(1) my.ini ํŒŒ์ผ ์ฐพ๊ธฐ

๊ฒฝ๋กœ : C:\ProgramData\MySQL\MySQL Server 5.7

 

(2) ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ my.iniํŒŒ์ผ ์—ด์–ด์„œ ์ˆ˜์ •ํ•˜๊ธฐ

๋ฉ”๋ชจ์žฅ ๋งˆ์šฐ์Šค์šฐํด๋ฆญํ•˜์—ฌ ๊ด€๋ฆฌ์ž๊ถŒํ•œ์œผ๋กœ ์—ด๊ธฐ, ๋ชจ๋“ ํŒŒ์ผ๋กœ my.ini์—ด๊ธฐ

 

 

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
init_connect='SET collation_connection = utf8_general_ci'
character-set-server=utf8

 

์ˆ˜์ •ํ•˜๊ธฐ

 

(3) mysql์žฌ์‹œ์ž‘

์ž‘์—…๊ด€๋ฆฌ์ž -> ์„œ๋น„์Šค-> ๋‹ค์‹œ์‹œ์ž‘

(4) ํ™•์ธํ•ด๋ณด๊ธฐ

 

*์ฃผ์˜ํ•  ์  : ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋ณ€๊ฒฝํ•˜๋ฉด ๋ณ€๊ฒฝ์ด ์•ˆ๋จ. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋งŒ๋“ค๊ธฐ ์ „ ์…‹ํŒ…ํ•˜๊ธฐ.

 

* ์œ ์ € ์ƒ์„ฑํ•˜๊ธฐ

create user 'jsp'@'%' identified by '1234';

create database jsp;

grant all privileges on jsp.* to 'jsp'@'%';

 

CREATE TABLE user(
id int AUTO_INCREMENT PRIMARY KEY, 
username varchar(20),
password varchar(100),
email varchar(30),
createTime timestamp

) ENGINE=InnoDB DEFAULT CHARSET = utf8; -- ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ • ํ•ด์คŒ, 2๊ฐ•์˜ ํ•œ๊ธ€์„ค์ •์—์„œ ์…‹ํŒ…ํ•ด๋†“์Œ.

CREATE TABLE board (
	id int AUTO_INCREMENT PRIMARY KEY, -- ์‹œํ€€์Šค๋ฅผ ์คŒ
	title varchar(100),
    content text(100000),
    userId int,
    createTime timestamp,
    FOREIGN KEY (userId) REFERENCES user (id) 
) ;

โ€‹

โ€‹

DB๋ฅผ ์—ฐ๊ฒฐํ•˜๊ธฐ์ „์—..

์›๋ž˜์˜ ํ•˜๋“œ๋””์Šคํฌ์ธ file system์„ ์กฐ๊ฐ์„ ๋‚ด์„œ DBsystem์˜์—ญ์œผ๋กœ๊ตฌ์กฐ๋กœ ๋ฐ”๊พธ๊ณ  DBMS๋กœ ์ ‘๊ทผํ•œ๋‹ค.

 

1. CLI : dos์ฐฝ์—์„œ mysql ๋ช…๋ น์–ด๋ฅผ ์จ์„œ ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ์‹

2. DBMS ํ”„๋กœ๊ทธ๋žจ : workbench(gui) ๋ฐฉ์‹์„ ์ด์šฉํ•˜์—ฌ

3. JAVA ์—์„œ ์ ‘๊ทผ : ์ŠคํŠธ๋ฆผ์„ ์—ฐ๊ฒฐํ•˜์—ฌ JDBC๊ฐ€ ํŒŒ์‹ฑํ•˜์—ฌ DBMS๋กœ ์—ฐ๊ฒฐ

โ€‹

์ž๋ฐ”๋นˆ : model, database์˜ table์„ java์˜ ๊ฐ์ฒด๋กœ ์˜ฎ๊ธด ๊ฒƒ

beanํŒŒ์ผ ์กด์žฌ