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, & �翬��);