{"id":688,"date":"2021-12-07T07:06:50","date_gmt":"2021-12-06T23:06:50","guid":{"rendered":"https:\/\/log.tanxiaodian.com\/?p=688"},"modified":"2021-12-31T11:53:00","modified_gmt":"2021-12-31T03:53:00","slug":"mysql%e4%b8%bb%e4%bb%8e%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/log.tanxiaodian.com\/?p=688","title":{"rendered":"mysql\u4e3b\u4ece\u8bbe\u7f6e"},"content":{"rendered":"\n<p>\u8f6c\u81eahttps:\/\/www.cnblogs.com\/atcloud\/p\/10773855.html<\/p>\n\n\n\n<p><a href=\"https:\/\/www.freesion.com\/article\/751871059\/\">\u914d\u7f6e\u670d\u52a1\u5668\u4e3b\u4ece\u540c\u6b65\u7684\u6b65\u9aa4\u65b9\u6cd5 &#8211; \u7070\u4fe1\u7f51\uff08\u8f6f\u4ef6\u5f00\u53d1\u535a\u5ba2\u805a\u5408\uff09 (freesion.com)<\/a><\/p>\n\n\n\n<h2 id=\"1\u4e3b\u4ece\u539f\u7406\">1\u3001\u4e3b\u4ece\u539f\u7406<\/h2>\n\n\n\n<p>\u4ece\u300a\u9ad8\u6027\u80fdmysql\u300b\u4e66\u4e2d\u8bb2\u89e3\u4e3b\u4ece\u539f\u7406\u5927\u81f4\u6709\u4e09\u4e2a\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ul><li>\u5728\u4e3b\u5e93\u4e0a\u628a\u6570\u636e\u66f4\u6539\u8bb0\u5f55\u5230\u4e8c\u8fdb\u5236\u65e5\u5fd7\u4e2d\uff08Binary Log\uff09\u4e2d\uff0c\u8fd9\u4e9b\u8bb0\u5f55\u79f0\u4e3a\u4e8c\u8fdb\u5236\u65e5\u5fd7\u4e8b\u4ef6\u3002<\/li><li>\u4ece\u5e93\u901a\u8fc7IO\u7ebf\u7a0b\u5c06\u4e3b\u5e93\u4e0a\u7684\u65e5\u5fd7\u590d\u5236\u5230\u81ea\u5df1\u7684\u4e2d\u7ee7\u65e5\u5fd7\uff08Relay Log\uff09\u4e2d\u3002<\/li><li>\u4ece\u5e93\u901a\u8fc7SQL\u7ebf\u7a0b\u8bfb\u53d6\u4e2d\u7ee7\u65e5\u5fd7\u4e2d\u7684\u4e8b\u4ef6\uff0c\u5c06\u5176\u91cd\u653e\u5230\u81ea\u5df1\u6570\u636e\u4e0a\u3002<\/li><\/ul>\n\n\n\n<p>\u539f\u7406\u56fe\u4e3a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"478\" src=\"https:\/\/log.tanxiaodian.com\/wp-content\/uploads\/2021\/12\/16388319771-1024x478.png\" alt=\"\" class=\"wp-image-689\" srcset=\"https:\/\/log.tanxiaodian.com\/wp-content\/uploads\/2021\/12\/16388319771-1024x478.png 1024w, https:\/\/log.tanxiaodian.com\/wp-content\/uploads\/2021\/12\/16388319771-300x140.png 300w, https:\/\/log.tanxiaodian.com\/wp-content\/uploads\/2021\/12\/16388319771-768x358.png 768w, https:\/\/log.tanxiaodian.com\/wp-content\/uploads\/2021\/12\/16388319771.png 1250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 id=\"2\u4e3b\u4ece\u914d\u7f6e\">2\u3001\u4e3b\u4ece\u914d\u7f6e<\/h2>\n\n\n\n<p>\u6f14\u793a\u7684\u73af\u5883\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u540d\u79f0<\/th><th>IP<\/th><\/tr><\/thead><tbody><tr><td>msyql-master\uff08\u4e3b\u5e93\uff09<\/td><td>192.168.197.135<\/td><\/tr><tr><td>mysql-slave\uff08\u4ece\u5e93\uff09<\/td><td>192.168.197.136<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u9996\u5148\u5728\u8fd9\u4e24\u53f0\u670d\u52a1\u5668\u5b89\u88c5mysql\u6570\u636e\u5e93\uff0c\u5b89\u88c5\u65b9\u6cd5\u53c2\u8003<a href=\"https:\/\/www.toutiao.com\/i6680112559154004484\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u300a\u79bb\u7ebf\u5b89\u88c5mysql\u6570\u636e\u5e93\u300b<\/a>\u3002<\/p>\n\n\n\n<p><strong>\uff081\uff09\u3001\u914d\u7f6e\u4e3b\u5e93<\/strong><\/p>\n\n\n\n<ul><li>\u4fee\u6539my.cnf\u6587\u4ef6\uff0c\u5728[mysqld]\u52a0\u5165\u4e0b\u9762\u7684\u5185\u5bb9\uff1a<code># \u670d\u52a1\u7684\u552f\u4e00\u7f16\u53f7 server-id = 1 # \u5f00\u542fmysql binlog\u529f\u80fd log-bin = mysql-bin # binlog\u8bb0\u5f55\u5185\u5bb9\u7684\u65b9\u5f0f\uff0c\u8bb0\u5f55\u88ab\u64cd\u4f5c\u7684\u6bcf\u4e00\u884c binlog_format = ROW # \u51cf\u5c11\u8bb0\u5f55\u65e5\u5fd7\u7684\u5185\u5bb9\uff0c\u53ea\u8bb0\u5f55\u53d7\u5f71\u54cd\u7684\u5217 binlog_row_image = minimal # \u6307\u5b9a\u9700\u8981\u590d\u5236\u7684\u6570\u636e\u5e93\u540d\u4e3ajgyw binlog-do-db = jgyw<\/code><\/li><li>\u4fee\u6539\u597d\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542fmysql\u670d\u52a1<code>service mysqld restart<\/code><\/li><li>\u521b\u5efa\u4ece\u5e93\u540c\u6b65\u6570\u636e\u7684\u8d26\u53f7<code>grant replication slave on *.* to 'jgyw'@'192.168.197.136' identified by 'jgyw@123'; flush privileges; <\/code><strong>\u6ce8\u610f\uff1a<\/strong>\u4e0a\u9762\u8fd9\u4e24\u4e2a\u547d\u4ee4\u662f\u5728mysql\u7684\u7ec8\u7aef\u6267\u884c\u7684\u3002<\/li><li>\u67e5\u770b\u4e3b\u5e93\u7684\u72b6\u6001\uff1amysql\u7684\u7ec8\u7aef\u6267\u884c:<code>show master status\\G; <\/code>\u8fd4\u56de\u7684\u4fe1\u606f\u4e3a\uff1a<code><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>**<em>* 1. row <strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>****<\/strong><strong>**<em>* File: mysql-bin.000002 Position: 2380 Binlog_Do_DB: jgyw Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec)<\/em><\/strong><\/em><\/strong><\/code><\/li><\/ul>\n\n\n\n<p><strong>\uff082\uff09\u3001\u914d\u7f6e\u4ece\u5e93<\/strong><\/p>\n\n\n\n<ul><li>\u4fee\u6539my.cnf\u6587\u4ef6\uff0c\u5728[mysqld]\u52a0\u5165\u4e0b\u9762\u7684\u5185\u5bb9\uff1a<code># \u670d\u52a1\u7684\u552f\u4e00\u7f16\u53f7 server-id = 2 # \u5f00\u542fmysql binlog\u529f\u80fd log-bin = mysql-bin # binlog\u8bb0\u5f55\u5185\u5bb9\u7684\u65b9\u5f0f\uff0c\u8bb0\u5f55\u88ab\u64cd\u4f5c\u7684\u6bcf\u4e00\u884c binlog_format = ROW # \u51cf\u5c11\u8bb0\u5f55\u65e5\u5fd7\u7684\u5185\u5bb9\uff0c\u53ea\u8bb0\u5f55\u53d7\u5f71\u54cd\u7684\u5217 binlog_row_image = minimal # \u6307\u5b9a\u9700\u8981\u590d\u5236\u7684\u6570\u636e\u5e93\u540d\u4e3ajgyw replicate-do-db = jgyw<\/code><\/li><li>\u4fee\u6539\u597d\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542fmysql\u670d\u52a1<code>service mysqld restart<\/code><\/li><li>\u6267\u884c\u540c\u6b65\u547d\u4ee4mysql\u7684\u7ec8\u7aef\u6267\u884c:<code># \u8bbe\u7f6e\u4e3b\u670d\u52a1\u5668ip\uff0c\u540c\u6b65\u8d26\u53f7\u5bc6\u7801\uff0c\u540c\u6b65\u4f4d\u7f6e change master to master_host='192.168.197.135',master_user='jgyw',master_password='jgyw@123',master_log_file='mysql-bin.000002',master_log_pos=2380; # \u5f00\u542f\u540c\u6b65\u529f\u80fd start slave;<\/code><\/li><li>\u67e5\u770b\u4ece\u5e93\u7684\u72b6\u6001mysql\u7684\u7ec8\u7aef\u6267\u884c:<code>show slave status\\G; <\/code>\u8fd4\u56de\u4fe1\u606f\u4e3a\uff1a<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/img2018.cnblogs.com\/blog\/840503\/201904\/840503-20190426134650424-1185202252.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>Slave_IO_Running\u548cSlave_SQL_Running\u7684\u72b6\u6001\u90fd\u4e3aYes\u65f6\uff0c\u8bf4\u660e\u4ece\u5e93\u914d\u7f6e\u6210\u529f\u3002<\/p>\n\n\n\n<h2 id=\"3\u6d4b\u8bd5\">3\u3001\u6d4b\u8bd5<\/h2>\n\n\n\n<p>\uff081\uff09\u3001\u5728<strong>\u4e3b\u5e93<\/strong>\u4e0a\u521b\u5efajgyw\u6a21\u5f0f\uff0c\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create schema jgyw;\n<\/code><\/pre>\n\n\n\n<p>\uff082\uff09\u3001\u5728<strong>\u4e3b\u5e93<\/strong>\u4e0a\u7684jgyw\u6a21\u5f0f\u91cc\u9762\u521b\u5efacomm_config\u8868\uff0c\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use jgyw;\nCREATE TABLE comm_config (configId varchar(200) NOT NULL ,configValue varchar(1024) DEFAULT NULL ,description varchar(2000) DEFAULT NULL ,PRIMARY KEY (configId)) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;\n<\/code><\/pre>\n\n\n\n<p>\uff083\uff09\u3001\u5728<strong>\u4e3b\u5e93<\/strong>\u4e0a\u5f80comm_config\u8868\u4e2d\u63d2\u5165\u4e00\u6761\u8bb0\u5f55\uff0c\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>insert into comm_config(configId, configValue, description) values('name', '\u67b6\u6784\u4e0e\u6211', '\u6d4b\u8bd5\u4e00\u4e0b');\n<\/code><\/pre>\n\n\n\n<p>\uff084\uff09\u3001\u5728<strong>\u4ece\u5e93<\/strong>\u4e0a\u67e5\u770b\u6a21\u5f0f\uff0c\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>show schemas;\n<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| jgyw               |\n| mysql              |\n| performance_schema |\n| sys                |\n+--------------------+\n5 rows in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>\u8bf4\u660ejgyw\u6a21\u5f0f\u540c\u6b65\u5230\u4ece\u5e93\u4e86<\/p>\n\n\n\n<p>\uff085\uff09\u3001\u5728<strong>\u4ece\u5e93<\/strong>\u4e0a\u67e5\u770bjgyw\u6a21\u5f0f\u4e0b\u7684\u8868\u53ca\u6570\u636e\uff0c\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use jgyw;\nshow tables;\n<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+----------------+\n| Tables_in_jgyw |\n+----------------+\n| comm_config    |\n+----------------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>\u8bf4\u660e\u8868\u4e5f\u540c\u6b65\u597d\u4e86\uff0c\u518d\u67e5\u770b\u6570\u636e\uff0c\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select * from comm_config;\n<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+----------+--------------+--------------+\n| configId | configValue  | description  |\n+----------+--------------+--------------+\n| name     | \u67b6\u6784\u4e0e\u6211     | \u6d4b\u8bd5\u4e00\u4e0b     |\n+----------+--------------+--------------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>\u8bf4\u660e\u6570\u636e\u4e5f\u540c\u6b65\u8fc7\u6765\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81eahttps:\/\/www.cnblogs.com&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/log.tanxiaodian.com\/?p=688\">Continue reading<span class=\"screen-reader-text\">mysql\u4e3b\u4ece\u8bbe\u7f6e<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[122],"_links":{"self":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/688"}],"collection":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=688"}],"version-history":[{"count":2,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/688\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/688\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}