MySQL mysqlbinlog¸¦ °¡Áø ÀÌ¿ø ±â·Ï ÆÄÀÏ (BinLog)¸¦ Àд ¹æ¹ý
MySQL µ¥ÀÌŸº£À̽º ¼¹ö´Â µ¥ÀÌŸº£À̽º¿¡ ÇàÁ¤°üÀÌ "Å볪¹« ±Ë" ¸Å°³º¯¼ö my.cny ±¸¼º ÆÄÀÏ¿¡ ÀÖ´Â ¹«´ÉÇÏ°Ô ÇÏÁö ¾Ê°Å³ª ¹ÛÀ¸·Î ³íÆòÇÏÁö ¾ÊÀ¸¸é À» Á¶°ÇÀ¸·Î, °¢ °Å·¡¸¦ À§ÇÑ ÀÌ¿ø ±â·Ï ÆÄÀÏÀ» »ý¼ºÇÑ´Ù. ÀÌ¿ø ±â·Ï ÆÄÀÏÀº ÀÌÁø Çü½Ä¿¡ ¾´´Ù. ½Ö¼º Å볪¹«, ¶Ç´Â ÀÏÄþî logbin°¡ MySQL µ¥ÀÌŸº£À̽º º¹Á¦ ¸ñÀûÀ» À§ÇØ ÁÖ·Î ÀÌ¿ëµÇ´õ¶óµµ, ¶§¶§·Î ´ç½ÅÀº ½ÃÇèÇÒ Çʿ䰡 ÀÖÀ» ¼öµµ ÀÖ´Ù ¶Ç´Â ½Ö¼ºÀÇ ³»¿ëÀ» Àбâ À§ÇÏ¿© mysqlbinlog °ø¿ëǰÀÌ µµ¿òÀÌ µÉ ¹®¼ Çü½ÄÀ» ·Î±×ÀÎÇÑ´Ù.
ÀÐÀ» °¡Ä¡°¡ ¾ø´Â ÀÌÁø Çü½Ä¿¡ ÀÖ´Â ¶§ /var/lib/mysql ÀüȹøÈ£ºÎ¿¡ ÀÖ´Â ÀϹÝÀûÀ¸·Î üÀç host_name-bin.xxxxxx¸¦ °¡Áø À̸§°ú »óÁ¡ÀÌ ÀÖ´Â, ÀÌ¿ø ±â·Ï ÆÄÀÏ¿¡´Â Áï½Ã ¿¸®°í ÀÐÀ» ¼ö ¾ø¾ú´Ù. ½Ö¼ºÀ» Àбâ À§ÇÏ¿©´Â ¹®¼ Çü½ÄÀ», ¿ì¸® ¶ÇÇÑ º¹Á¦ üÁ¦¿¡ ³ë¿¹°°Àº ¼¹ö¿¡ ÀÇÇØ ¾²´Â readrelay ±â·Ï ÆÄÀÏ¿¡ ´É·Â ÀÖ´Â mysqlbinlog ¸í·ÉÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù ·Î±×ÀÎÇÑ´Ù. ¸±·¹ÀÌ Å볪¹«¿¡´Â ÀÌ¿ø ±â·Ï ÆÄÀϰú µ¿ÀÏÇÑ Ã¼Àç°¡ ÀÖ´Ù.
mysqlbinlog °ø¿ëǰÀ» »ç¿ëÇÏ´Â °ÍÀº SSH¸¦ ÅëÇØ ¹þ±â±â À§ÇÏ¿© °£´ÜÇÏ, »Ñ¸® (±×¹Û¿¡ ´ç½ÅÀº »ç¿ëÀÚ ¸í°ú ¾ÏÈ£¸¦ ÁöÁ¤ÇØ¾ß ÇÑ´Ù)·Î ·Î±×ÀÎ ÈÄ¿¡ mysqlbinlog¸¦ ¾ÈÀ¸·Î ºñµµ·Ï °£´ÜÇÏ°Ô µÚ¿¡ ¿À´Â ¸í·É Åë¾î·ÐÀ» ÀÌ¿ëÇÑ´Ù:
log_file mysqlbinlog [¼±ÅñÇ]¡¦
ÀÌ·¸°Ô ÀÌ¿ø ±â·Ï ÆÄÀÏÀÇ ³»¿ëÀ» Ç¥½ÃÇÏ´Â °ÍÀº Àаí binlog.000001¸¦, »ç¿ëÇÑ´Ù ÀÌ ¸í·ÉÀ» Áö¸íÇß´Ù:
mysqlbinlog binlog.000001
ÀÌ¿ø ±â·Ï ÆÄÀÏ ¹× ±×°ÍÀÇ ÀÚ·á´Â ¾ÆÁÖ °Å´ëÇÏ°Ô ÇÒ °Í °°, µû¶ó¼ ½ºÅ©¸°¿¡ ¹«¾ùÀ̵çÀ» Àд °ÍÀ» °ÅÀÇ ºÒ°¡´ÉÇÑ ÇÑ. ±×·¯³ª, ´ç½ÅÀº ¹®¼ ÆíÁý±â¿¡¼ ³ªÁß¿¡ ã¾Æº¸±â¸¦ À§ÇØ µÚ¿¡ ¿À´Â ¸í·ÉÀ» »ç¿ëÇØ¼ ¿©´Â, ÀÏ ¼ö ÀÖ´Â ÆÄÀÏ·Î mysqlbinlogÀÇ »êÃâÀ» ¹è°üÇÒ ¼ö ÀÖ´Ù:
mysqlbinlog binlog.000001 > filename.txt
ÀÌ¿ø Å볪¹«¿¡¼ ¸¸È¸µÈ ÀÚ·á ¾çÀ» °¨¼Ò½Ã۱â À§ÇÏ¿©´Â, µ¹·Áº¸³»Áö´Â ÀڷḦ Á¦ÇÑÇϱâ À§ÇÏ¿© ÀÌ¿ëµÉ ¼ö ÀÖ´Â ¸î¸î ¼±ÅñÇÀÌ ÀÖ´Ù. À¯¿ëÇÑ ±×µéÀÇ »çÀÌ¿¡¼ ¾Æ·¡¿Í °°ÀÌ ¿°ÅµÇ½Ê½Ã¿À:
- start-datetime=datetime
°ú µ¿µîÇÑ Å¸ÀÓ ½ºÅÆÇÁ°¡ Àִ ù¹øÂ° »ç°Ç¿¡ ÀÌ¿ø Å볪¹«¸¦ Àд ½ÃÀÛ ¶Ç´Â ³¯Â¥-½Ã°£ ³íÀï º¸´Ù´Â ³ªÁß¿¡. ³¯Â¥-½Ã°£ °¡Ä¡´Â ´ç½ÅÀÌ mysqlbinlog¸¦ ´Þ¸®´Â ±â°è¿¡ ÇöÁö ½Ã°£´ë¿¡ °ü·ÃµÈ ÀÌ´Ù. °¡Ä¡´Â ³¯Â¥ ½Ã°£ ¶Ç´Â ŸÀÓ ½ºÅÆÇÁ¸¦ À§ÇØ ¹Þ¾Æµé¿©Áø üÀç¿¡ ÀÚ·á À¯Çü ÀÖ¾î¾ß ÇÑ´Ù. ¿¹¸¦ µé¸é:
mysqlbinlog --start-datetime= " 2005-12-25 11:25: 56 " binlog.000001
- stop-datetime=datetime
³¯Â¥-½Ã°£ ³íÀï¿¡ ŸÀÓ ½ºÅÆÇÁ µ¿µîÇÑ °Í ¶Ç´Â Èĺΰ¡ Àִ ù¹øÂ° »ç°Ç¿¡ ÀÌ¿ø Å볪¹«¸¦ Àд Á¤Áö. ÀÌ ¼±ÅñÇÀº point-in-time ȸº¹À» À§ÇØ À¯¿ëÇÏ´Ù. ³¯Â¥-½Ã°£ °¡Ä¡¿¡ °üÇÏ¿© Á¤º¸¸¦ À§ÇÑ - ½ÃÀÛÇÏ ³¯Â¥-½Ã°£ ¼±ÅñÇÀÇ ¹¦»ç¸¦ º¸½Ê½Ã¿À.
- start-position=N
N ³íÀï°ú µ¿µîÇÑ À§Ä¡°¡ Àִ ù¹øÂ° »ç°Ç¿¡ ÀÌ¿ø Å볪¹«¸¦ Àд ½ÃÀÛ. This option applies to the first log file named on the command line.
–stop-position=N
Stop reading the binary log at the first event having a position equal or greater than the N argument. This option applies to the last log file named on the command line.
For more usage information on mysqlbinlog, visit here.
IMPORTANT: This is a machine translated page which is provided "as is" without warranty. Machine translation may be difficult to understand. Please refer to original English article whenever possible.
Share and contribute or get technical support and help at My Digital Life Forums.
Related Articles
- Change or Set MySQL Long Query Time Value for log-slow-queries
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 1
- Reset the Root Password of MySQL Server
- MySQL Database Performance Tuning Best Practices Video Tutorial
- Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - Part 3
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4
- Change and Reset MySQL root Password
- How to Find and Replace Text in MySQL Database using SQL

































June 29th, 2008 16:33
This post saved my life today¡¦ when the binary log were the only way to retrieve important data get lost¡¦ thanks!!