Home > DB > ๐Ÿ’พ[Database] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—… ๋ฐฉ๋ฒ•.

๐Ÿ’พ[Database] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—… ๋ฐฉ๋ฒ•.
Database

๐Ÿ’พ[Database] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—… ๋ฐฉ๋ฒ•.

  • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—…์€ ์‚ฌ์šฉํ•˜๋Š” DBMS(Database Management System)์— ๋”ฐ๋ผ ๋ฐฉ๋ฒ•์ด ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
    • ์ด ํฌ์ŠคํŠธ์—์„œ๋Š” MySQL์„ ์˜ˆ์‹œ๋กœ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

1๏ธโƒฃ MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—….

  • MySQL์—์„œ mysqldump ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋ฐฑ์—…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

1๏ธโƒฃ ์ „์ฒด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—….

  • ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด MySQL ์„œ๋ฒ„์˜ ์ „์ฒด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋ฐฑ์—…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    mysqldump -u [์‚ฌ์šฉ์ž ์ด๋ฆ„] -p --all-databases > backup.sql
    
  • ์œ„ ๋ช…๋ น์–ด๋Š” ์ „์ฒด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋ฐฑ์—…์„ backup.sql ํŒŒ์ผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

2๏ธโƒฃ ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฑ์—….

  • ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋งŒ ๋ฐฑ์—…ํ•˜๋ ค๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    mysqldump -u [์‚ฌ์šฉ์ž ์ด๋ฆ„] -p [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„] > [ํŒŒ์ผ ์ด๋ฆ„].sql
    
  • ์˜ˆ๋ฅผ ๋“ค์–ด, library๋ผ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋ฐฑ์—…ํ•˜๋ ค๋ฉด:
    mysqldump -u root -p library > library_backup.sql
    

3๏ธโƒฃ ํŠน์ • ํ…Œ์ด๋ธ”๋งŒ ๋ฐฑ์—….

  • ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋‚ด์—์„œ ํŠน์ • ํ…Œ์ด๋ธ”๋งŒ ๋ฐฑ์—…ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ…Œ์ด๋ธ” ์ด๋ฆ„์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    mysqldump -u [์‚ฌ์šฉ์ž ์ด๋ฆ„] -p [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„] [ํ…Œ์ด๋ธ” ์ด๋ฆ„] > [ํŒŒ์ผ ์ด๋ฆ„].sql
    
  • ์˜ˆ๋ฅผ ๋“ค์–ด, library ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ book ํ…Œ์ด๋ธ”๋งŒ ๋ฐฑ์—…ํ•˜๋ ค๋ฉด:
    mysqldump -u root -p library book > book_backup.sql
    

4๏ธโƒฃ ๋ฐฑ์—… ์‹œ ์˜ต์…˜ ์ถ”๊ฐ€.

  • ๋ฐฑ์—… ํŒŒ์ผ์„ ๋” ์•ˆ์ „ํ•˜๊ฒŒ ์ €์žฅํ•˜๊ฑฐ๋‚˜, ํŠธ๋ฆฌ๊ฑฐ์™€ ๊ฐ™์€ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • --add-drop-table : ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๊ธฐ ์ „์— ๊ธฐ์กด ํ…Œ์ด๋ธ”์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.
    • --routines : ํ”„๋กœ์‹œ์ € ๋ฐ ํ•จ์ˆ˜ ํฌํ•จ.
    • --triggers : ํŠธ๋ฆฌ๊ฑฐ ํฌํ•จ.
    • --single-transaction : ๋ฐฑ์—… ์ค‘ ํŠธ๋žœ์žญ์…˜์„ ๋ณด์žฅํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ผ๊ด€์„ฑ ์žˆ๊ฒŒ ๋ฐฑ์—…ํ•ฉ๋‹ˆ๋‹ค.
    • ์˜ˆ:
        mysqldump -u root -p --single-transaction --add-drop-table --triggers library > library_full_backup.sql
      

5๏ธโƒฃ ๋ฐฑ์—… ํŒŒ์ผ ๋ณต์›

  • ๋ฐฑ์—… ํŒŒ์ผ์„ ๋ณต์›ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด mysql ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    mysql -u [์‚ฌ์šฉ์ž ์ด๋ฆ„] -p [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„] < [ํŒŒ์ผ ์ด๋ฆ„].sql
    
  • ์˜ˆ๋ฅผ ๋“ค์–ด, library_backup.sql์„ ๋ณต์›ํ•˜๋ ค๋ฉด:
    mysql -u root -p library < library_backup.sql
    
  • ์ฐธ๊ณ  : ๋ฐฑ์—… ํŒŒ์ผ์„ ๋ณต์›ํ•  ๋•Œ๋Š” ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ๋ฏธ๋ฆฌ ์ƒ์„ฑ๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.