{"id":710,"date":"2014-08-04T13:44:24","date_gmt":"2014-08-04T13:44:24","guid":{"rendered":"http:\/\/pingtool.org\/?p=710"},"modified":"2014-08-23T14:55:27","modified_gmt":"2014-08-23T14:55:27","slug":"mysql-replication-configuration","status":"publish","type":"post","link":"https:\/\/pingtool.org\/ru\/mysql-replication-configuration\/","title":{"rendered":"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u044b MySQL"},"content":{"rendered":"<p>\u0420\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441\u043e \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u044b\u043c.<\/p>\n<p>\t<strong><\/p>\n<li>\u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/li>\n<p><\/strong><\/p>\n<p>\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b \/etc\/my.cnf<\/p>\n<p><code><br \/>\nserver-id=1<br \/>\nlog_bin=\/var\/log\/mysql\/mysql-bin.log<br \/>\n<\/code><\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b <strong>log_bin<\/strong> \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u044b.<br \/>\n\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <strong> binlog_do_db=database <\/strong> \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0431\u0430\u0437, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0444\u0430\u0439\u043b, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f (\u0441\u043c\u043e\u0442\u0440\u0438 <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/replication-options-binary-log.html\" title=\"\u0441\u0441\u044b\u043b\u043a\u0443\" target=\"_blank\">\u0441\u0441\u044b\u043b\u043a\u0443<\/a>)<\/p>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440 MySQL:<br \/>\n<code>service mysql restart<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445.<br \/>\n\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c MySQL:<br \/>\n<code>mysql -u root -p<\/code><br \/>\n\u0418 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443<br \/>\n<code>GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'pass';<br \/>\nFLUSH PRIVILEGES;<\/code><\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0430\u043c\u043f \u0431\u0430\u0437\u044b \u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440.<br \/>\n\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443.<br \/>\n\u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 MySQL:<br \/>\n<code>FLUSH TABLES READ LOCK;<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u043d\u0435\u0442\u0441\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f.<br \/>\n<code>SHOW MASTER STATUS;<\/code><br \/>\n\u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f Position.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0430\u043c\u043f.<br \/>\n\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u043e\u043a\u043d\u043e, \u0438\u043d\u0430\u0447\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435,<br \/>\n\u0431\u0430\u0437\u0430 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0412 \u043d\u043e\u0432\u043e\u043c \u043e\u043a\u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<br \/>\n<code>mysqldump -u root -p -f db1 &gt; db1.sql<\/code><br \/>\n\u0433\u0434\u0435 db1 &#8212; \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438<\/p>\n<p>\u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u0437\u0443:<br \/>\n\u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 MySQL:<br \/>\n<code>UNLOCK TABLES;<\/code><\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\t<strong><\/p>\n<li>\u0412\u0442\u043e\u0440\u0438\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/li>\n<p><\/strong><\/p>\n<p>\u041d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u0443, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 &#8212; db1.<br \/>\n\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 MySQL:<br \/>\n<code>CREATE DATABASE db1;<\/code><br \/>\n\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043b\u0438\u0442\u044c \u0432 \u043d\u0435\u0435 \u0434\u0430\u043c\u043f \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430<br \/>\n(\u0412\u044b \u0432\u0435\u0434\u044c \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b db1.sql \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440?)<br \/>\n<code>mysql -u root -p -f db1 &lt; db1.sql<\/code><br \/>\n\u0413\u043e\u0442\u043e\u0432\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u043f\u0438\u044f \u0431\u0430\u0437\u044b \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<p>\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c  \u043a\u043e\u043d\u0444\u0438\u0433 MySQL \/etc\/my.cnf \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<p><code>server-id=2<br \/>\nrelay-log=\/var\/log\/mysql\/mysql-relay-bin.log<br \/>\nlog_bin=\/var\/log\/mysql\/mysql-bin.log<br \/>\n<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c:<br \/>\n<code>service mysql restart<\/code><\/p>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438!<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043e\u0434\u0438\u043d \u0448\u0430\u0433, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<br \/>\n\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c MySQL \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<br \/>\n<code>CHANGE MASTER TO<br \/>\nMASTER_HOST='IP-\u0430\u0434\u0440\u0435\u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430',<br \/>\nMASTER_USER='slave_user',<br \/>\nMASTER_PASSWORD='pass',<br \/>\nMASTER_LOG_FILE='mysql-bin.000001',<br \/>\nMASTER_LOG_POS=XXX;<\/code><\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043f\u043e\u043b\u0435 Position \u0438\u0437 &#171;SHOW MASTER STATUS&#187; \u0438 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043c\u0435\u0441\u0442\u043e XXX.<br \/>\n\u0418 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e:<br \/>\n<code>START SLAVE;<\/code><\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435:<br \/>\n<code>SHOW SLAVE STATUS\\G<\/code><\/p>\n<p>Slave_IO_State: Waiting for master to send event<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e<br \/>\n<code>STOP SLAVE<\/code><\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438!<\/p>\n<p>PS: \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f TCP \u043f\u043e\u0440\u0442 3306, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e \u0444\u0430\u0435\u0440\u0432\u043e\u043b\u044b.<\/p>","protected":false},"excerpt":{"rendered":"<p>\u0420\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441\u043e \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u044b\u043c. \u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b \/etc\/my.cnf server-id=1 log_bin=\/var\/log\/mysql\/mysql-bin.log \u0412 \u0444\u0430\u0439\u043b log_bin \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u044b. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c binlog_do_db=database \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0431\u0430\u0437, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0444\u0430\u0439\u043b, \u043e\u0434\u043d\u0430\u043a\u043e &hellip; <a href=\"https:\/\/pingtool.org\/ru\/mysql-replication-configuration\/\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[12],"tags":[52],"class_list":["post-710","post","type-post","status-publish","format-standard","hentry","category-linux","tag-mysql"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":12,"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"predecessor-version":[{"id":732,"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/posts\/710\/revisions\/732"}],"wp:attachment":[{"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pingtool.org\/ru\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}