๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ปTech/๐ŸฌMySQL

[MySQL] dump ๋ฐ import ๋ฐฉ๋ฒ•

by _viper_ 2019. 6. 3.
๋ฐ˜์‘ํ˜•

mysql dump ๋ฐ import ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

 

โ—พ DB backup (dump)

1. ํ…Œ์ด๋ธ” ๋ฐฑ์—…

mysqldump --single-transaction -u user -p'password' DB_NM TABLE_NM > table_nm.sql

--single-transaction : ํ•˜๋‚˜์˜ ํŠธ๋žœ์žญ์…˜์œผ๋กœ dump ์ˆ˜ํ–‰ 

  • ์šฉ๋Ÿ‰์ด ํฐ ํ…Œ์ด๋ธ” dump ํ•  ๊ฒฝ์šฐ ํ•ด๋‹น ํ…Œ์ด๋ธ” lock ๊ฑธ๋ฆผ, ์ด ์˜ต์…˜์„ ์‚ฌ์šฉํ•ด์ค˜์•ผ DB lock ๊ฑธ๋ฆฌ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

2. DB ์ „์ฒด ๋ฐฑ์—…

mysqldump --single-transaction --all-databases -u user -p'password' > db_nm.sql

 

โ—พ dump sql ํŒŒ์ผ ์ ์šฉ (import)

mysql -u user -p'password' DB_NM < table_nm.sql