{"id":156489,"date":"2012-10-29T09:18:04","date_gmt":"2012-10-29T05:18:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=156489"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=156489","title":{"rendered":"<span class=\"post_title\">\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 INSERT\u2026 ON DUPLICATE KEY UPDATE \u0432 \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0434\u0435\u043b\u044c \u043d\u0430\u0437\u0430\u0434, \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043d\u0430\u0434 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0411\u0414 \u0438 \u0434\u0430\u0436\u0435 \u0435\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0438 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0435 4 \u043d\u0435\u0434\u0435\u043b\u0438. \u041d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0432 \u0436\u0435\u043b\u0435\u0437\u0435 \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445. \u0412 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u0430 \u043e\u0434\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438, \u043a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0447\u0435\u0433\u043e, <code>INT AUTO_INCREMENT PRIMARY KEY<\/code> \u0438 <code>UNIQUE KEY<\/code>.<\/p>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441\u044b, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0441 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0431\u044b\u043b\u0438 \u0442\u0438\u043f\u0430 <code>INSERT ... ON DUPLICATE KEY UPDATE<\/code> (\u0434\u0430\u043b\u0435\u0435 \u2014 <code>INSERT ODKU<\/code>), \u0433\u0434\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 <code>INSERT<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \u0441 <code>UNIQUE KEY<\/code>. \u0418 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043e\u043d\u0438 \u0441 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439, \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e 1500-2000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e 24 \u0447\u0430\u0441\u0430 \u0432 \u0441\u0443\u0442\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0440\u043e\u0448\u0438 \u0432 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u0432 \u0447\u0435\u043c \u0434\u0435\u043b\u043e.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043a\u0430\u043a \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u043a \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"sql\">CREATE TABLE update_test (   id INT UNSIGNED NOT NULL AUTO_INCREMENT,   username VARCHAR(20) NOT NULL,   host_id TINYINT UNSIGNED NOT NULL,   last_modified TIMESTAMP NULL DEFAULT NULL,   PRIMARY KEY(id),   UNIQUE KEY(username) ) ENGINE=InnoDB; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439:<\/p>\n<pre><code class=\"sql\">(root@localhost) [test]&gt; INSERT INTO update_test (username, host_id, last_modified) VALUES ('foo',3,NOW()); Query OK, 1 row affected (0.00 sec)  (root@localhost) [test]&gt; select * from update_test; +----+----------+---------+---------------------+ | id | username | host_id | last_modified       | +----+----------+---------+---------------------+ | 1  | foo      |       3 | 2012-10-05 22:36:30 | +----+----------+---------+---------------------+ <\/code><\/pre>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e, \u0434\u0430? \u041c\u044b \u0432\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043e\u0434\u0438\u043d \u0440\u044f\u0434 \u0432 \u043f\u0443\u0441\u0442\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c <code>SHOW CREATE TABLE<\/code>, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0441\u0447\u0451\u0442\u0447\u0438\u043a <code>AUTO_INCREMENT<\/code> \u0441\u0435\u0439\u0447\u0430\u0441 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>2<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c <code>INSERT ODKU<\/code> \u0432 \u044d\u0442\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"sql\">(root@localhost) [test]&gt; insert into update_test (username,host_id) values ('foo',1) on duplicate key update last_modified=NOW(); Query OK, 2 rows affected (0.00 sec)  (root@localhost) [test]&gt; select * from update_test; +----+----------+---------+---------------------+ | id | username | host_id | last_modified       | +----+----------+---------+---------------------+ |  1 | foo      |       3 | 2012-10-05 22:58:28 | +----+----------+---------+---------------------+ 1 row in set (0.00 sec) <\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0432\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u0440\u044f\u0434, \u043d\u0430\u0448 \u0441\u0447\u0451\u0442\u0447\u0438\u043a <code>AUTO_INCREMENT<\/code> \u0432\u044b\u0440\u043e\u0441 \u0434\u043e <code>3<\/code>. \u042d\u0442\u043e, \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. InnoDB \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u0438 <code>PRIMARY KEY<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0434\u0451\u0442 \u043f\u0435\u0440\u0432\u044b\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 MySQL \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u0448 <code>INSERT<\/code>, \u0432\u0438\u0434\u0438\u0442, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>AUTO_INCREMENT<\/code> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0435\u0433\u043e, \u043d\u043e \u043f\u043e\u0442\u043e\u043c, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 <code>UNIQUE KEY<\/code> \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e <code>INSERT<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 <code>UPDATE<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438 <code>handler status<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0431\u044b\u043b \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u0441\u0442\u0430\u0432\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u043d\u0435\u0443\u0434\u0430\u0447\u0435\u0439, \u0438 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0448\u0451\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e (\u044d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b 2 \u0440\u044f\u0434\u0430, \u0430 \u043d\u0435 1).<\/p>\n<pre><code class=\"sql\">(root@localhost) [test]&gt; show status like 'handler%';  *** some rows omitted *** +----------------------------+-------+ | Variable_name              | Value | +----------------------------+-------+ | Handler_commit             | 1     | | Handler_rollback           | 0     | | Handler_update             | 1     | | Handler_write              | 1     | +----------------------------+-------+ <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u2014 \u00ab\u041d\u0443 \u0438 \u0447\u0442\u043e?\u00bb. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443. 1500 <code>INSERT ODKU<\/code> \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e 24 \u0447\u0430\u0441\u0430 \u0432 \u0441\u0443\u0442\u043a\u0438. <code>PRIMARY KEY<\/code> \u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u2014 <code>INT UNSIGNED<\/code>. \u0421\u0447\u0438\u0442\u0430\u0435\u043c. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>INT UNSIGNED<\/code> \u2013 \u044d\u0442\u043e <code>4294967295<\/code>. \u0414\u0435\u043b\u0438\u043c \u044d\u0442\u043e \u043d\u0430 1500 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0438 \u0434\u0435\u043b\u0438\u043c \u043d\u0430 86400, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0435\u043a\u0443\u043d\u0434 \u0432 \u0441\u0443\u0442\u043a\u0430\u0445, \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c 33.1 \u0434\u043d\u0435\u0439, \u0438\u043b\u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c 4 \u043d\u0435\u0434\u0435\u043b\u0438. \u0421\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435? \u042f \u0442\u0430\u043a \u043d\u0435 \u0434\u0443\u043c\u0430\u044e. \u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f? \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u0441 \u0443\u0434\u0438\u0432\u0438\u0442\u044c. \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0435 \u0440\u044f\u0434 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0441 <code>AUTO_INCREMENT<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d.<\/p>\n<pre><code class=\"sql\">(root@localhost) [test]&gt; insert into update_test (id,username,host_id) values (4294967295, 'bar', 10); Query OK, 1 row affected (0.00 sec) (root@localhost) [test]&gt; flush status; (root@localhost) [test]&gt; insert into update_test (username,host_id) values ('baz', 10); ERROR 1062 (23000): Duplicate entry '4294967295' for key 'PRIMARY'  (root@localhost) [test]&gt; show status like 'handler%';  *** some rows omitted *** +----------------------------+-------+ | Variable_name              | Value | +----------------------------+-------+ | Handler_rollback           | 1     | | Handler_write              | 1     | +----------------------------+-------+ <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u044f\u0434 \u0438 \u044d\u0442\u043e \u043d\u0435 \u0432\u044b\u0448\u043b\u043e, \u0442.\u043a. <code>AUTO_INCREMENT<\/code> \u0443\u0436\u0435 \u0438\u043c\u0435\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u043f\u0440\u043e\u0448\u0451\u043b. \u041d\u043e, \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>INSERT ODKU<\/code>? \u0421\u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:<\/p>\n<pre><code class=\"sql\">(root@localhost) [test]&gt; select * from update_test; +------------+----------+---------+---------------------+ | id         | username | host_id | last_modified       | +------------+----------+---------+---------------------+ |          1 | foo      |       3 | 2012-10-05 22:58:28 | | 4294967295 | bar      |      10 | NULL                | +------------+----------+---------+---------------------+ 2 rows in set (0.00 sec)  (root@localhost) [test]&gt; INSERT INTO update_test (username, host_id) VALUES ('foo', 7) ON DUPLICATE KEY UPDATE host_id=7, last_modified=NOW(); Query OK, 2 rows affected (0.00 sec) <\/code><\/pre>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0434\u0430? 2 \u0440\u044f\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u044f\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0443\u0441\u043b\u043e\u0432\u0438\u044e <code>username = &quot;foo&quot;<\/code>, \u0431\u044b\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u044b <code>host_id<\/code> \u0438 <code>last_modified<\/code>, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"sql\">(root@localhost) [test]&gt; select * from update_test; +------------+----------+---------+---------------------+ | id         | username | host_id | last_modified       | +------------+----------+---------+---------------------+ |          1 | foo      |       3 | 2012-10-05 22:58:28 | | 4294967295 | bar      |       7 | 2012-10-05 23:24:49 | +------------+----------+---------+---------------------+ 2 rows in set (0.00 sec) <\/code><\/pre>\n<p>  \u041e\u043f\u0430, \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d \u0431\u044b\u043b \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u044f\u0434, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e <code>id<\/code> \u0440\u0430\u0432\u0435\u043d \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e <code>AUTO_INCREMENT<\/code>, \u0430 <code>UNIQUE KEY<\/code> \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>username<\/code> \u0431\u044b\u043b \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0432 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0447\u044c\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b\u0430 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430. 1500 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043f\u044b\u0442\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0440\u044f\u0434, \u043d\u0438 \u043a \u0447\u0435\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443 \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 <code>AUTO_INCREMENT<\/code>-\u0441\u0442\u043e\u043b\u0431\u0446\u0430 c <code>INT<\/code> \u043d\u0430 <code>BIGINT<\/code>.<\/p>\n<p>  \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/insert-on-duplicate.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e<\/a>. \u041c\u0430\u043d\u0443\u0430\u043b \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u043d\u0430\u0448 <code>INSERT ODKU<\/code> \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438, \u0431\u0443\u0434\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0443 <code>UPDATE update_test SET host_id = 7, last_modified = NOW() WHERE id = 4294967295 OR username = &quot;foo&quot; LIMIT 1<\/code> \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 <code>PRIMARY<\/code>, \u043d\u0435\u0436\u0435\u043b\u0438 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u044b\u0439 <code>UNIQUE<\/code>.<\/p>\n<h4>\u0427\u0435\u043c\u0443 \u0436\u0435 \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c?<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u0418\u0441\u0447\u0435\u0440\u043f\u0430\u0442\u044c <code>AUTO_INCREMENT<\/code> \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043b\u0435\u0433\u0447\u0435, \u0447\u0435\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f. \u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u043c\u0435\u043d\u0435\u0435 500k \u0440\u044f\u0434\u043e\u0432.<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>SIGNED<\/code> \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f <code>AUTO_INCREMENT<\/code> \u2014 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u0434\u0435\u044f. \u0412\u044b \u0442\u0435\u0440\u044f\u0435\u0442\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/li>\n<li>\u0418\u043d\u0442\u0443\u0438\u0446\u0438\u044f, \u043f\u043e\u0434\u043e\u0431\u043d\u043e \u0437\u0430\u043a\u043e\u043d\u0430\u043c \u0444\u0438\u0437\u0438\u043a\u0438, \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u0438\u0442 \u0432 \u043a\u0440\u0430\u0439\u043d\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445.<\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/156489\/\"> http:\/\/habrahabr.ru\/post\/156489\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0434\u0435\u043b\u044c \u043d\u0430\u0437\u0430\u0434, \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043d\u0430\u0434 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0411\u0414 \u0438 \u0434\u0430\u0436\u0435 \u0435\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0438 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0435 4 \u043d\u0435\u0434\u0435\u043b\u0438. \u041d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0432 \u0436\u0435\u043b\u0435\u0437\u0435 \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445. \u0412 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u0430 \u043e\u0434\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438, \u043a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0447\u0435\u0433\u043e, <code>INT AUTO_INCREMENT PRIMARY KEY<\/code> \u0438 <code>UNIQUE KEY<\/code>.<\/p>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441\u044b, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0441 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0431\u044b\u043b\u0438 \u0442\u0438\u043f\u0430 <code>INSERT ... ON DUPLICATE KEY UPDATE<\/code> (\u0434\u0430\u043b\u0435\u0435 \u2014 <code>INSERT ODKU<\/code>), \u0433\u0434\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 <code>INSERT<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \u0441 <code>UNIQUE KEY<\/code>. \u0418 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043e\u043d\u0438 \u0441 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439, \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e 1500-2000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e 24 \u0447\u0430\u0441\u0430 \u0432 \u0441\u0443\u0442\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0440\u043e\u0448\u0438 \u0432 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u0432 \u0447\u0435\u043c \u0434\u0435\u043b\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-156489","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/156489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156489"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/156489\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}