MySQL ¹é¾÷ ¹× Ãæµ¹ ó¸®
CSE À̾߱â/Programming 2007/09/10 21:44
MySQLÀ» »ç¿ëÇÏ´Ù º¸¸é ¹é¾÷ÇÒ ÀÏÀÌ ÀÇ¿Ü·Î ¸¹ÀÌ »ý±ä´Ù. ±×¸®°í °¡²û Å×À̺íÀ̳ª DB°¡ ³ª°¡¼ °íÃÄ¾ß µÈ´Ù. (»ç½Ç °³ÀÎÀûÀ¸·Î´Â ÀÌ·± ÀÏÀÌ º°·Î »ý±âÁö ¾Ê´Âµ¥, ³ªÇÑÅ× ºÎŹÇÏ´Â »ç¶÷µéÀº ¿Ö ²À ÀÌ·± ÀÏÀÌ ¹ß»ýÇÏ´ÂÁö ¸ð¸£°Ú´Ù.) ¾Æ¹«Æ° ÀÌ·± ÀÏÀ» ´çÇÏ¸é °íÃÄ¾ß µÇ´Âµ¥, MySQLÀ» Ç×»ó »ç¿ëÇÏ°í ÀÖÁö ¾ÊÀ¸¸é ¸í·É¾î°¡ »ý°¢³ªÁö ¾Ê´Â´Ù. °Ë»öÇؼ ¾Ë¾Æ³½ ±è¿¡ ºí·Î±×¿¡ Á¤¸®ÇØ ³ö¾ß°Ú´Ù.
1. ¹é¾÷(dump)
$> mysqldump -u[user_id] -p DB_name [table_name1 table_name2 ...] > file_name
- ½©¿¡¼ ÀÛ¾÷ÇÑ´Ù.
- table_name±îÁö Àû¾îÁÖ¸é DBÀÇ tableÀ» dumpÇÏ°Ô µÈ´Ù.
- ex) mysqldump -usangmin -p board > board.sql
- ex) mysqldump -usangmin -p board freeboard > board_freeboard.sql
<Âü°í> tableÀÇ ¿øÇÏ´Â °ª¸¸ dumpÇϱâ
$> mysqldump -usangmin -p board freeboard -w'no=>1 and no=<10' > board_freeboard.sql
- Á¶°Ç¹®À» -w ´ÙÀ½¿¡ ''·Î ¹¾î¼ Àû¾îÁØ´Ù.
<Âü°í> DB schema¸¸ dumpÇϱâ
$> mysqldump -usangmin -p -d board > board.sql
$> mysqldump -usangmin -p -d board freeboard > board_freeboard.sql
[¿É¼Ç ¼³¸í] -d : schema¸¸ ¹é¾÷
-t : data¸¸ ¹é¾÷
<Âü°í> MySQL ¹öÀü 4.1 -> 4.0 À¸·Î ´Ù¿î±×·¹ÀÌµå ½Ã
$> mysqldump --compatible=mysql40 -usangmin -p DB_name > file_name
2. º¹±¸
$> mysql -u[user_id] -p [DB_name] < file_name
- mysqldump°¡ ¾Æ´Ï°í mysqlÀÌ´Ù.
- DB_nameÀ» Àû¾îÁÖ¸é ÁöÁ¤ÇÑ DB·Î tableÀ» ³ÖÀ» ¼ö ÀÖ´Ù.
- ex) mysql -usangmin -p < board.sql
- ex) mysql -usangmin -p board < board_freeboard.sql
3. ÅؽºÆ® ÆÄÀÏ·Î µ¥ÀÌÅÍ ÀúÀå ¹× º¹±¸
- mysql Ä¿¸Çµå »ó¿¡¼ ½ÇÇàÇÑ´Ù.
1) ÀúÀå
mysql> SELECT field1, field2.... INTO OUTFILE 'file_name' FIELDS TERMINATED BY '|' FROM table_name WHERE condition;
- '|'´Â ±¸ºÐÀÚ(delimeter)ÀÓ.
2) º¹±¸
mysql> LOAD DATA INFILE 'file_name' INTO TABLE table_name FIELDS TERMINATED BY '|' ;
4. Å×À̺í Ãæµ¹ üũ ¹× º¹±¸
°¡²û ÀÌ·± ¸Þ½ÃÁö¸¦ º¼ ¼ö Àִµ¥, ±×·¯¸é Å×ÀÌºí ´ýÇÁµµ ¾È µÇ°í Á¦´ë·Î accessµµ ¾È µÇ´Â °æ¿ì°¡ ÀÖ´Ù.
Database failed to execute query (query) 1016: Can't open file: 'sometable.MYI'. (errno: 145)
ÀÌ·² °æ¿ì ´ÙÀ½ÀÇ ¸í·ÉÀ» ÀÌ¿ëÇÏ¸é ¹®Á¦¸¦ ÇØ°á ÇÒ ¼ö ÀÖ´Ù.
1) Ãæµ¹ üũ
mysql> CHECK TABLE table_name;
- ¿¡·¯°¡ ÀÖÀ¸¸é ¿¡·¯¶ó°í ³ª¿Â´Ù.
2) º¹±¸
mysql> REPAIR TABLE table_name;
- OK°¡ ³ª¿À°í ´Ù½Ã CHECK TABLE·Î È®ÀÎÇØ º¸¸é OK°¡ ³ª¿À´Â °ÍÀ» ¾Ë ¼ö ÀÕ´Ù.
- º¹¼öÇÏ´Â °úÁ¤¿¡¼ µ¥ÀÌÅÍÀÇ ¼Õ½ÇÀÌ ÀÖÀ» ¼öµµ ÀÖ´Ù.
<Âü°í> http://www.modwest.com/help/kb6-230.html
http://www.databasejournal.com/features/mysql/article.php/3300511
[MySQL] table º¹»ç, º¹Á¦Çϱâ ð½º=) Database
2006/01/13 11:51
http://blog.naver.com/bigenius/20020676555
1. ¿ø·¡ ÀÖ´ø Å×À̺íÀ» À̸§¸¸ ¹Ù²ã¼ »õ·Î ¸¸µé°í ½ÍÀ» ¶§,
create table »õ·Î¿îÅ×À̺í¸í select * from ¿øº»Å×À̺í¸í
2. Å×ÀÌºí ½ºÅ°¸¶°¡ °°Àº °æ¿ì µ¥ÀÌŸ¸¦ º¹»çÇÏ°í ½ÍÀ» ¶§,
insert into tableA select * from tableB
ÁÁÀº±â´ÉÀ̳׿ä
by ¹Ì¼Ò𽺠(http://blog.naver.com/bigenius
|