๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Back-end/DB

[MySQL] ๊ฑด๋ฌผ DB ๋ฐ์ดํ„ฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ERD ์„ค๊ณ„ ๋ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์ถ•ํ•ด๋ณด๊ธฐ

728x90
๋ฐ˜์‘ํ˜•

๐ŸŸก ๋„๋กœ๋ช… ์ฃผ์†Œ DB๋ฅผ ์ œ๊ณตํ•˜๋Š” ์‚ฌ์ดํŠธ์—์„œ ๊ฑด๋ฌผ DB ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์šด ๋ฐ›์•„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์ถ•!

โค๏ธ OS : Rocky Linux

โค๏ธ DB : Maria DB

 

โœ… ์ดˆ๊ธฐ ํ™˜๊ฒฝ ์„ธํŒ…

Step 1. ๊ฑด๋ฌผ DB ์ž๋ฃŒ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•˜์—ฌ ๋‹ค์šด๋กœ๋“œ

https://www.juso.go.kr/addrlink/addressBuildDevNew.do?menu=rdnm 

 

๊ฑด๋ฌผDB | ๋„๋กœ๋ช…์ฃผ์†Œ DB ๋‹ค์šด๋กœ๋“œ | ๋„๋กœ๋ช…์ฃผ์†Œ ๊ฐœ๋ฐœ์ž์„ผํ„ฐ

* ์ตœ๊ทผ 2๋…„ ์ด๋‚ด ์ž๋ฃŒ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. * 19.8์›” ์›”๋ณ€๋™๋ถ„๋ถ€ํ„ฐ ๊ด€๋ จ์ง€๋ฒˆ ๋ณ€๋™๋ถ„์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.

www.juso.go.kr

 

Step2. ๋ฐ์ดํ„ฐ ๋ชจ๋ธ๋ง์„ ์œ„ํ•œ ํ”„๋กœ๊ทธ๋žจ์ธ ERwin ๋‹ค์šด๋กœ๋“œ

https://www.erwin.com/

 

Data Governance & Data Modeling | erwin

erwin software provides data governance and data modeling along with fast, accurate insights guiding risk management, innovation, and digital transformation.

www.erwin.com

[Products & Services]-[ERwin Data Modeler]-[Start Trial]์„ ํด๋ฆญ!

 

 

 

โœ… ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์ถ•

Step1. ERwin์„ ํ™œ์šฉํ•˜์—ฌ ERD ๊ทธ๋ฆฌ๊ธฐ

์ด ์ •๋ณด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ERD ์„ค๊ณ„

 

 

Step2. MariaDB์— jusoDB ๊ตฌ์ถ• (CLI ํ™˜๊ฒฝ์—์„œ ์ƒˆ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑํ•˜๊ธฐ)
create database juso;

jusoDB๊ฐ€ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค!

 

 

Step3. jusoDB ์„ ํƒ ๋ฐ ์‚ฌ์šฉ์ž ์ƒ์„ฑ
use juso

์ƒ์„ฑํ•œ jusoDB๋ฅผ ์„ ํƒ

 

create user '์‚ฌ์šฉ์ž๋ช…' identified by '๋น„๋ฐ€๋ฒˆํ˜ธ';

์‚ฌ์šฉ์ž ์ƒ์„ฑ์™„๋ฃŒ

 

 

Step4. ์‚ฌ์šฉ์ž ๊ถŒํ•œ ๋ถ€์—ฌ
grant all privileges on juso.* to '์‚ฌ์šฉ์ž๋ช…'@'%';
GRANT FILE ON *.* TO '์‚ฌ์šฉ์ž๋ช…'@'%';

-> ์šฐ๋ฆฌ๋Š” ์ฃผ์†Œ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ํŒŒ์ผ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ๋„ ๋ถ€์—ฌํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค!!!

flush privileges;

 

 

Step5. ์ƒ์„ฑ๋œ ์‚ฌ์šฉ์ž์˜ ๊ถŒํ•œ์„ ๊ฐ€์ง€๊ณ  ์ ‘์†
exit

-> ๋‚˜๊ฐ”๋‹ค๊ฐ€ ๋‹ค์‹œ ์ ‘์†

 

mysql -u '์‚ฌ์šฉ์ž' -p '์‚ฌ์šฉํ•  DB ์ด๋ฆ„'

์„ค์ •ํ•œ ์‚ฌ์šฉ์ž์™€ pwd ์ž…๋ ฅ์„ ํ†ตํ•ด jusoDB ์ ‘์†ํ•˜๊ธฐ!

 

 

Step6. ํ…Œ์ด๋ธ” ์ƒ์„ฑ
# ๊ฑด๋ฌผ ์ •๋ณด ํ…Œ์ด๋ธ”
CREATE TABLE BUILDING
(
	DCD                  CHAR(10) NULL,
	SIDO                 VARCHAR(40) NULL,
	GUGUN                VARCHAR(40) NULL,
	DONG                 VARCHAR(40) NULL,
	RI                   VARCHAR(40) NULL,
	SAN                  CHAR(1) NULL,
	GBM                  NUMERIC(4) NULL,
	GBS                  NUMERIC(4) NULL,
	RCD                  CHAR(12) NULL,
	ROAD                 VARCHAR(80) NULL,
	SUB                  CHAR(1) NULL,
	BNM                  NUMERIC(5) NULL,
	BNS                  NUMERIC(5) NULL,
	BLD                  VARCHAR(40) NULL,
	BDF                  VARCHAR(100) NULL,
	BNO                  CHAR(25) NOT NULL,
	DNO                  CHAR(2) NULL,
	HDCD                 CHAR(10) NULL,
	HDONG                VARCHAR(40) NULL,
	ZIP                  CHAR(5) NULL,
	ZNO                  CHAR(3) NULL,
	BULK                 VARCHAR(40) NULL,
	MOVED                CHAR(2) NULL,
	EDATE                VARCHAR(8) NULL,
	OROAD                VARCHAR(25) NULL,
	SGBLD                VARCHAR(40) NULL,
	APT                  CHAR(1) NULL,
	GICHO                CHAR(5) NULL,
	DETAIL               CHAR(1) NULL,
	NOTE1                VARCHAR(15) NULL,
	NOTE2                VARCHAR(15) NULL
);



ALTER TABLE BUILDING
ADD PRIMARY KEY (BNO);
# ๊ด€๋ จ ์ง€๋ฒˆ ํ…Œ์ด๋ธ”
CREATE TABLE JIBUN
(
	DCD                  CHAR(10) NULL,
	SIDO                 VARCHAR(40) NULL,
	GUGUN                VARCHAR(40) NULL,
	DONG                 VARCHAR(40) NULL,
	RI                   VARCHAR(40) NULL,
	SAN                  CHAR(1) NULL,
	GBM                  NUMERIC(4) NULL,
	GBS                  NUMERIC(4) NULL,
	RCD                  CHAR(12) NOT NULL,
	SUB                  CHAR(1) NOT NULL,
	BNM                  NUMERIC(5) NOT NULL,
	BNS                  NUMERIC(5) NOT NULL,
	GNO                  NUMERIC(10) NOT NULL,
	MOVED                CHAR(2) NULL
);



ALTER TABLE JIBUN
ADD PRIMARY KEY (RCD,SUB,BNM,BNS,GNO);
# ๋„๋กœ๋ช… ์ฝ”๋“œ ํ…Œ์ด๋ธ”
CREATE TABLE ROAD_CODE
(
	SCD                  CHAR(5) NOT NULL,
	RNO                  CHAR(7) NOT NULL,
	ROAD                 VARCHAR(80) NULL,
	EROAD                VARCHAR(80) NULL,
	DNO                  CHAR(2) NOT NULL,
	SIDO                 VARCHAR(40) NULL,
	GUGUN                VARCHAR(40) NULL,
	DONGGB               CHAR(1) NULL,
	DONGCD               CHAR(3) NULL,
	DONG                 VARCHAR(40) NULL,
	PNO                  CHAR(7) NULL,
	PROAD                VARCHAR(80) NULL,
	STATE                CHAR(1) NULL,
	MODI                 CHAR(1) NULL,
	MINFO                VARCHAR(14) NULL,
	ESIDO                VARCHAR(40) NULL,
	EGUGUN               VARCHAR(40) NULL,
	EDONG                VARCHAR(40) NULL,
	GOSI                 VARCHAR(8) NULL,
	MALSO                VARCHAR(8) NULL
);



ALTER TABLE ROAD_CODE
ADD PRIMARY KEY (SCD,RNO,DNO);

-> ์œ„์™€ ๊ฐ™์ด ์ฟผ๋ฆฌ๋ฌธ์„ ์ž…๋ ฅํ•˜์—ฌ ํ•„์š”ํ•œ ํ…Œ์ด๋ธ”๋“ค์„ ์ƒ์„ฑํ•œ๋‹ค.

 

ํ…Œ์ด๋ธ” ์ƒ์„ฑ ํ™•์ธ

 

 

Step7. ๊ฑด๋ฌผ DB ๋ฐ์ดํ„ฐ -> ๋‚˜์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‚ฝ์ž…

 

๐Ÿ˜‚ txt ํŒŒ์ผ์„ DB์— import ํ•˜๋Š” ๋ฐฉ๋ฒ•

load data infile '๋‚ด ํŒŒ์ผ์ด ์œ„์น˜ํ•œ ๊ฒฝ๋กœ' into table ํ…Œ์ด๋ธ”๋ช… fields terminated by '๊ตฌ๋ถ„์ž' lines terminated by '\n'

์ด๋Ÿฐ์‹์œผ๋กœ ํŒŒ์ผ์ด ์—…๋กœ๋“œ ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค!

 

importํ•œ ๋ฐ์ด๋” ๊ฐœ์ˆ˜ ํ™•์ธ์™„๋ฃŒ!

 

 

 

 

 

์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฐœ์ƒํ–ˆ๋˜ ์ด์Šˆ๋“ค ๐Ÿ’จ

1. ๋ฆฌ๋ˆ…์Šค ํŠน์ • ํŒŒ์ผ๋ช…๋งŒ ์‚ญ์ œํ•˜๋Š” ๋ฐฉ๋ฒ•
https://ye5ni.tistory.com/144
2. ๋ฆฌ๋ˆ…์Šค ํ•œ๊ธ€ ๊นจ์ง ๋ฌธ์ œ ํ•ด๊ฒฐ
https://ye5ni.tistory.com/145
3. ํŒŒ์ผ ์ธ์ฝ”๋”ฉ ํ˜•์‹ ํ™•์ธ ๋ฐ ๋ณ€๊ฒฝ๋ฐฉ๋ฒ•
https://ye5ni.tistory.com/142
4. ๋ฆฌ๋ˆ…์Šค ์‰˜ & Xshell์—์„œ ์ ˆ๋Œ€๊ฒฝ๋กœ ํ‘œ์‹œํ•˜๊ธฐ
https://ye5ni.tistory.com/140
5. ์ฟผ๋ฆฌ ์ž‘์„ฑ์‹œ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•
https://ye5ni.tistory.com/141

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•