mysql

What is auto reconnect in MySQL? mysql ÀÚµ¿ À翬°áÀÌ ¹«¾ùÀԴϱî?

The MySQL client library can perform an automatic reconnect to the server if it finds that the connection is down when you attempt to send a statement to the server to be executed. the mysql Ŭ¶óÀÌ¾ðÆ® ¶óÀ̺귯¸®¸¦ ÀÚµ¿À¸·Î ´Ù½Ã ¿¬°áÀ» ¼öÇàÇÒ ¼öÀÖ½À´Ï´Ù°¡ ¹ß°ßÇÏ´Â °æ¿ì ¼­¹ö·ÎÀÇ ¿¬°áÀº ¾Æ·¡¸¦ º¸³»´Â ¼º¸íÀ» ½ÃµµÇÒ ¶§ ¼­¹ö¸¦ ½ÇÇàÇÕ´Ï´Ù. In this case, the library tries once to reconnect to the server and send the statement again. ÀÌ °æ¿ì¿¡´Â ¶óÀ̺귯¸®¸¦ ¼­¹ö¿¡ ´Ù½Ã ¿¬°áÇÏ·Á°í ½Ãµµ¸¦ ÇÑ ¹ø ´­·¯ ¹®ÀåÀ» ´Ù½Ã Àü¼ÛÇÕ´Ï´Ù.

Automatic reconnection can be convenient because you need not implement your own reconnect code, but if a reconnection does occur, several aspects of the connection state are reset and your application will not know about it. ÀÚµ¿À¸·Î ´Ù½Ã ¿¬°áÀ» ±¸ÇöÇÒ ¼öÀÖ½À´Ï´Ù Æí¸®ÇÑ ¿Ö³ÄÇÏ¸é ´ç½Å ÀÚ½ÅÀÇ ¿¬°á Äڵ带 Çʿ䰡 ¾ø´Ù,ÇÏÁö¸¸ ´Ù½Ã°¡ ¹ß»ýÇϸé, ¿©·¯ Ãø¸é¿¡ ¿¬°á »óŸ¦ ´Ù½Ã ¼³Á¤ÇÏ¿© ÀÀ¿ë ÇÁ·Î±×·¥°ú ±×°Í¿¡ ´ëÇØ ¾Ë ¼ö¾ø½À´Ï´Ù. This is extremely useful if you long running persistent connections to the database. À̰ÍÀº ¸Å¿ì ±ä °æ¿ì¿¡ À¯¿ëÇÕ´Ï´ÙÀ» µ¥ÀÌÅͺ£À̽º¿¡ ¿µ±¸ÀûÀÎ Á¢¼ÓÀ» ½ÇÇàÇÕ´Ï´Ù. Also if you have too many sql queries / use connection pool etc. auto reconnect is a handy feature. ¶ÇÇÑ ³Ê¹« ¸¹Àº °æ¿ì¿¡´Â sql °Ë»ö¾î / ¿¬°á Ç®¸µÀ» »ç¿ë µîµî ÀÚµ¿ À翬°áÀÌ Æí¸®ÇÑ ±â´ÉÀ»ÇÕ´Ï´Ù. Let's look at how to enable / disable auto reconnect in MySQL and what are the side-effects of enabling auto reconnect. ¸¦ Ȱ¼ºÈ­ÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ »ìÆìº¸°Ú / ÇØÁ¦ mysql ÀÚµ¿ À翬°á¿¡¼­ ¿ì¸®´Â ¹«¾ùÀ» Ȱ¼ºÈ­ ¿· - ¿µÇâÀ» ÀÚµ¿ À翬°áÇÕ´Ï´Ù.

How to enable MySQL client auto reconnect mysql Ŭ¶óÀÌ¾ðÆ®¸¦ Ȱ¼ºÈ­ÇÏ´Â ¹æ¹ý ÀÚµ¿ À翬°á

my_bool reconnect = 1; my_bool À翬°á = 1;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect); mysql_options (& mysql, mysql_opt_reconnect, & À翬°á);

What are the side-effects of MySQL auto reconnect? - ¿µÇâÀ» Ãø¸éÀº ¹«¾ùÀԴϱî mysql ÀÚµ¿ À翬°á?

  • Any active transactions are rolled back and autocommit mode is reset. ¸ðµç Ȱ¼º Æ®·£Àè¼ÇÀÌ ·Ñ¹é ¹× autocommit ¸ðµå°¡¸¦ Àç¼³Á¤ÇÕ´Ï´Ù.
  • All table locks are released. ¸ðµç Å×À̺íÀ» Àá±ÝÀÌ ÇØÁ¦ÇÕ´Ï´Ù.
  • All TEMPORARY tables are closed (and dropped). ¸ðµç Àӽà Å×À̺íÀº Æó¼â (±×¸®°í Ç϶ô).
  • Session variables are reinitialized to the values of the corresponding variables. ¼¼¼Ç º¯¼ö´Â ÇØ´ç º¯¼öÀÇ °ªÀ»À» ´Ù½Ã ÃʱâÈ­ÇÕ´Ï´Ù. This also affects variables that are set implicitly by statements such as SET NAMES. ÀÌ ¶ÇÇÑ ¾Ï½ÃÀûÀ¸·Î ¿µÇâÀ» ¹ÌÄ¡´Â º¯¼ö°¡ÀÌ ¼³Á¤°ú °°Àº ¹®ÀåÀ¸·Î À̸§À» ¼³Á¤ÇÕ´Ï´Ù.
  • User variable settings are lost. »ç¿ëÀÚ º¯¼ö ¼³Á¤ÀÌ ¼Õ½ÇÇÕ´Ï´Ù.
  • Prepared statements are released. ÁغñµÈ ¸í·É¹®ÀÌ ÇØÁ¦ÇÕ´Ï´Ù.
  • HANDLER variables are closed. 󸮱⠺¯¼ö°¡ Æó¼âÇÕ´Ï´Ù.
  • The value of LAST_INSERT_ID() is reset to 0. ÀÇ °ªÀ» last_insert_id ()´Â ¸®¼ÂÀ» 0À¸·ÎÇÕ´Ï´Ù.
  • Locks acquired with GET_LOCK() are released. Àá±Ý ÀåÄ¡¸¦ Ãëµæ get_lock ()°¡ Ãâ½ÃÇÕ´Ï´Ù.
  • mysql_ping() does not attempt a reconnection if the connection is down. mysql_ping () ´Ù½Ã ¿¬°áÀ» ½ÃµµÇÏÁö ¾Ê½À´Ï´Ù ¿¬°áÀÌ °æ¿ì¿¡´Â ¾Æ·¡ÇÕ´Ï´Ù. It returns an error instead. ´ë½Å¿¡ ±×°Í¿¡ ¿À·ù¸¦ ¹ÝȯÇÕ´Ï´Ù.

Source ±Ù¿ø

How to disable MySQL client auto reconnect mysql Ŭ¶óÀÌ¾ðÆ® ÀÚµ¿ À翬°á ±â´ÉÀ» ÇØÁ¦ÇÏ´Â ¹æ¹ý

In view of the side-effects you may want to disable auto reconnect. - È¿°ú¸¦ º¼ ¼öÀÖ´Â Ãø¸é¿¡¼­ »ç¿ëÇÏÁö ¾Êµµ·Ï ¼³Á¤ÇÒ ¼öÀÖ½À´Ï´Ù ÀÚµ¿ À翬°áÇÕ´Ï´Ù. In MySQL version 5.1 and above auto reconnect is disabled by default. mysql ¹öÀü 5.1 À̻󿡼­ ÀÚµ¿ À翬°áÀº ±âº»ÀûÀ¸·Î »ç¿ëµÇÁö ¾Ê½À´Ï´Ù. In any version you can disable auto reconnect with the following PHP code: ¸ðµç ¹öÀü¿¡¼­ ÀÚµ¿ ´Ù½Ã ¿¬°áÀ» ÇØÁ¦ÇÒ ¼öÀÖ½À´Ï´Ù ´ÙÀ½°ú °°Àº ÄÚµå :
my_bool reconnect = 0; my_bool À翬°á = 0;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect); mysql_options (& mysql, mysql_opt_reconnect, & À翬°á);