{"id":260216,"date":"2015-06-26T19:47:02","date_gmt":"2015-06-26T15:47:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=260216"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=260216","title":{"rendered":"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL + octopus"},"content":{"rendered":"<p>             <img decoding=\"async\" src=\"http:\/\/fc01.deviantart.net\/fs36\/f\/2008\/265\/b\/0\/sand_Dolphin_and_octopus_by_ClassyFat.jpg\"\/><\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c MySQL \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f gem&#8217;a octopus, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. <br \/>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0440\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430(\u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f Master&#8217;a, \u0442\u0440\u0435\u0442\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 Slave&#8217;a), \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b octopus \u0440\u0430\u0431\u043e\u0442\u0430\u043b. <br \/>  <a name=\"habracut\"><\/a><br \/>  <b>\u0428\u0430\u0433 \u043f\u0435\u0440\u0432\u044b\u0439 \u2014 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432<\/b><br \/>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430 Master \u2014 \u043c\u0430\u0448\u0438\u043d\u0435, \u0442\u0430\u043a \u0438 \u043d\u0430 Slave.<\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c MySQL. <\/p>\n<pre><code class=\"bash\">sudo apt-get install mysql-server<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u0434\u0435\u043c \u0432 MySQL \u043a\u043e\u043d\u0441\u043e\u043b\u044c:   <\/p>\n<pre><code class=\"bash\">mysql -u root -p<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0434\u0430\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u043e\u0439:  <\/p>\n<pre><code class=\"bash\">create database rails_myapp; GRANT ALL ON rails_myapp.* TO 'rails_myapp_user'@'localhost'; GRANT ALL ON rails_myapp.* TO 'rails_myapp_user'@'%'; FLUSH PRIVILEGES; EXIT;<\/code><\/pre>\n<p>  <b>\u0428\u0430\u0433 \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c Master<\/b><br \/>  \u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 MySQL \u043d\u0430 Master \u2014 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<pre><code class=\"bash\">sudo nano \/etc\/mysql\/my.cnf<\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0412\u043e \u2014 \u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430\u0439\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"bash\">bind-address            = 127.0.0.1<\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u043d\u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 IP \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 0.0.0.0, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u0434\u043e\u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430:<\/p>\n<pre><code class=\"bash\">bind-address            = 0.0.0.0<\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u0448\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f server-id, \u0438\u0449\u0435\u043c server-id \u0432 [mysqld] \u0441\u0435\u043a\u0446\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0430. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 server-id, \u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043b\u0443\u0447\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c 1, \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438. <\/p>\n<p>  \u0415\u0449\u0435 \u0440\u0430\u0437 \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u0442\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430. <\/p>\n<pre><code class=\"bash\">server-id               = 1<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c log_bin. Slave \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043b\u043e\u0433\u0435. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441 log_bin:<\/p>\n<pre><code class=\"bash\">log_bin                 = \/var\/log\/mysql\/mysql-bin.log<\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435 \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 Slave \u2014 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0437, \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044f \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u0430\u0437, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0440\u0435\u043f\u043b\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"bash\">binlog_do_db            = rails_myapp<\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0434\u0435\u043b\u0430\u043d\u044b! \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b. <\/p>\n<p>  \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c MySQL.<\/p>\n<pre><code class=\"bash\">sudo service mysql restart<\/code><\/pre>\n<p>  \u041e\u0442\u043a\u0440\u043e\u0435\u043c MySQL \u2014 \u0448\u0435\u043b\u043b.<\/p>\n<pre><code class=\"bash\">mysql -u root -p<\/code><\/pre>\n<p>  \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0434\u043b\u044f Slave. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"bash\">GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0432\u043e\u044e \u0431\u0430\u0437\u0443:<\/p>\n<pre><code class=\"bash\">USE  rails_myapp;<\/code><\/pre>\n<p>  \u0417\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430\u043c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u044d\u0442\u0430\u043f\u0430\u0445:<\/p>\n<pre><code class=\"bash\">FLUSH TABLES WITH READ LOCK;<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0431\u0435\u0440\u0435\u043c:<\/p>\n<pre><code class=\"bash\">SHOW MASTER STATUS;<\/code><\/pre>\n<p>  \u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443, \u0435\u0441\u043b\u0438 \u043d\u0430\u0431\u0435\u0440\u0435\u0442\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"bash\">mysql&gt; SHOW MASTER STATUS;<\/code><\/pre>\n<p>  +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>  | File | Position | Binlog_Do_DB| <br \/>  +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>  | mysql-bin.000001 | 107 | rails_myapp | <br \/>  +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>  1 row in set (0.00 sec)<\/p>\n<p>  \u0412\u0430\u0436\u043d\u043e! \u0417\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0438\u043b\u0438 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0437\u0436\u0435.<br \/>  \u041f\u043e\u043a\u0430 \u0432\u0430\u0448\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u043d\u0443\u0436\u043d\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 rails_myapp. \u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0432 \u043d\u043e\u0432\u043e\u043c \u043e\u043a\u043d\u0435, \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u043d\u0430\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 bash \u2014 \u0448\u0435\u043b\u0435, \u0430 \u043d\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435 MySQL.<\/p>\n<pre><code class=\"bash\">mysqldump -u root -p --opt rails_myapp &gt; rails_myapp.sql<\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 MySQL \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0439\u0442\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445(\u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044c).<\/p>\n<pre><code class=\"bash\">UNLOCK TABLES; QUIT;<\/code><\/pre>\n<p>  \u0412\u0441\u0435! \u041c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 Master&#8217;a.<\/p>\n<p>  <b>\u0428\u0430\u0433 \u0442\u0440\u0435\u0442\u0438\u0439 \u2014 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c Slave. <\/b><br \/>  \u0417\u0430\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 MySQL \u0441\u0435\u0440\u0432\u0435\u0440, \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 MySQL \u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445(\u0438\u043c\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0435, \u043a\u0430\u043a \u0438 \u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0435):<\/p>\n<pre><code class=\"bash\">CREATE DATABASE rails_myapp; EXIT;<\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0438\u0442\u0435 \u0444\u0430\u0439\u043b \u0441 SQL \u2014 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0438\u043c\u043f\u043e\u0440\u0442.<\/p>\n<pre><code class=\"bash\">mysql -u root -p rails_myapp&lt; \/path\/to\/rails_myapp.sql<\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 MySQL: <\/p>\n<pre><code class=\"bash\">sudo nano \/etc\/mysql\/my.cnf<\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442 server-id. \u041a\u0430\u043a \u0412\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u043d\u043e\u043c\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0433\u0440\u0443\u043f\u043f\u044b(\u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 Master&#8217;a \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 1).<\/p>\n<pre><code class=\"bash\">server-id               = 2<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u043f\u0438\u0448\u0435\u043c(\u0438\u043b\u0438 \u043e\u0442\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c) \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u043a\u0438: <\/p>\n<pre><code class=\"bash\">relay-log               = \/var\/log\/mysql\/mysql-relay-bin.log log_bin                 = \/var\/log\/mysql\/mysql-bin.log binlog_do_db            = newdatabase<\/code><\/pre>\n<p>  \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bind-address: <\/p>\n<pre><code class=\"bash\">bind-address            = 0.0.0.0 <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c MySQL:<\/p>\n<pre><code class=\"bash\">sudo service mysql restart<\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438. \u041f\u043e\u043c\u043d\u0438\u0442\u0435! \u0412\u043c\u0435\u0441\u0442\u043e MASTER_LOG_FILE \u0438 MASTER_LOG_POS \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e.<\/p>\n<pre><code class=\"bash\">CHANGE MASTER TO MASTER_HOST='12.34.56.789',MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=  107; START SLAVE; <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0443\u0434\u0430\u0447\u043d\u043e \u043b\u0438 \u043f\u0440\u043e\u0448\u0435\u043b \u0437\u0430\u043f\u0443\u0441\u043a Slave&#8217;a? \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u043c\u0430\u043d\u0434\u0443, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435 \u0438 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043b\u043e\u0433: <\/p>\n<pre><code class=\"bash\">SHOW SLAVE STATUS\\G<\/code><\/pre>\n<p>  <b>\u0428\u0430\u0433 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 \u2014 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c octopus.<\/b><br \/>  \u0412 Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 Gemfile:<\/p>\n<pre><code class=\"bash\">gem 'ar-octopus'<\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 config\/ \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b shards.yml, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 Slave \u2014 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041f\u043e\u043c\u043d\u0438\u0442\u0435! \u0424\u0430\u0439\u043b database.yml \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e Master&#8217;a, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 shards.yml \u0437\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e Slave&#8217;\u043e\u0432, \u00a0\u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0432 YML \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0438 \u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u0438 \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0424\u0430\u0439\u043b shards.yml, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\"> octopus:   replicated: true   fully_replicated: true   environments:     - development     - test   development:     slave:       adapter: mysql2       encoding: utf8       database: rails_myapp       username: rails_myapp_user       password: qqdq       host: 130.111.11.111       port: 3306       pool: 10   test:     slave:       adapter: mysql2       encoding: utf8       database: rails_myapp       username: rails_myapp_user       password: qqdq       host: 130.111.111.111       port: 3306       pool: 10<\/code><\/pre>\n<p>  \u0412\u0441\u0435! \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0412\u0430\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445, \u0447\u0442\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f replicated_model(), \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0432 POST \u2014 \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435 \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: <\/p>\n<pre><code class=\"bash\"> [Shard: slave]  OurModel Load (1.0ms)  SELECT  `model`.* FROM `model` WHERE `chats`.`id` = 'gkjhgfhd' LIMIT 1<\/code><\/pre>\n<p>  <b>\u0423\u0434\u0430\u0447\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438!<\/b>             <\/p>\n<div class=\"clear\"><\/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\/261251\/\"> http:\/\/habrahabr.ru\/post\/261251\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>             <img decoding=\"async\" src=\"http:\/\/fc01.deviantart.net\/fs36\/f\/2008\/265\/b\/0\/sand_Dolphin_and_octopus_by_ClassyFat.jpg\"\/><\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c MySQL \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f gem&#8217;a octopus, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. <br \/>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0440\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430(\u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f Rails \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f Master&#8217;a, \u0442\u0440\u0435\u0442\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 Slave&#8217;a), \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b octopus \u0440\u0430\u0431\u043e\u0442\u0430\u043b.   <\/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-260216","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/260216","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=260216"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/260216\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=260216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=260216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=260216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}