{"id":553,"date":"2024-12-10T15:57:32","date_gmt":"2024-12-10T07:57:32","guid":{"rendered":"http:\/\/192.168.5.24\/?p=553"},"modified":"2025-01-09T17:33:51","modified_gmt":"2025-01-09T09:33:51","slug":"mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%e4%b8%8e%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/bigvip.dpdns.org\/?p=553","title":{"rendered":"Mariadb\u4e3b\u4ece\u590d\u5236\u4e0e\u8bfb\u5199\u5206\u79bb\u914d\u7f6e"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4e3b\u4ece\u590d\u5236\u7684\u5b9e\u73b0                   <\/h2>\n\n\n\n<p>         \u5b89\u88c5mysql\u6570\u636e\u5e93\u4e00\u4e3b\u4e8c\u4ece\u5171\u4e09\u53f0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u4e3b\u6570\u636e\u5e93\u7684\u914d\u7f6e\uff1a<\/strong>\n\n1\u3001\u5728\/etc\/my.cnf\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e24\u884c\n      server-id=01\n      log-bin=mysql-index\n\n2\u3001\u5efa\u7acb\u540c\u6b65\u8d26\u53f7\u5e76\u6388\u6743\n  GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123456';\n\n3\u3001\u91cd\u65b0\u6570\u636e\u5e93\n    systemctl restart mariadb\n\n4\u3001\u67e5\u770b\u4e3b\u6570\u636e\u5e93\u7684\u72b6\u6001\n&#91;root@localhost ]# mysql -uroot -p\nMariaDB &#91;(none)]> show master status;\n+--------------------+----------+--------------+------------------+\n| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |\n+--------------------+----------+--------------+------------------+\n| mysql-index.000001 |      455 |              |                  |\n+--------------------+----------+--------------+------------------+\n1 row in set (0.00 sec)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u4ece\u6570\u636e\u5e93\u7684\u914d\u7f6e\uff1a<\/strong>\n\n1\u3001\u5728\/etc\/my.cnf\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u884c\n     server-id=02\n    ----\u4ece\u5e932\u4fee\u6539server-id=03,\u5176\u5b83\u914d\u7f6e\u4e0e\u4ece\u5e931\u7684\u8bbe\u7f6e\u4e00\u6837\u3002\n2\u3001\u91cd\u65b0\u6570\u636e\u5e93\n    systemctl restart mariadb\n\n3\u3001\u767b\u5f55\u8fdb\u5165mysql\u547d\u4ee4\u884c\uff0c\u5148\u505c\u6b62slave\n\n     stop slave;\n    \n4\u3001\u4fee\u6539\u914d\u7f6e\n\nCHANGE MASTER TO\n  MASTER_HOST='192.168.168.146',\n  MASTER_USER='slave',\n  MASTER_PASSWORD='123456',\n  MASTER_PORT=3306,\n  MASTER_LOG_FILE='mysql-index.000001',\n  MASTER_LOG_POS=455,\n  MASTER_CONNECT_RETRY=10;\n\n5\u3001\u91cd\u542fslave\u8fdb\u7a0b\n   start slave;\n\n6\u3001\u67e5\u770b\u4ece\u6570\u636e\u5e93\u8fd0\u884c\u72b6\u6001\n Slave_IO_Running: Yes            Slave_SQL_Running: Yes  \u5373\u8bf4\u660e\u8fd0\u884c\u6b63\u5e38\u3002\n\nMariaDB &#91;(none)]> show slave status\\G;\n*************************** 1. row ***************************\n               Slave_IO_State: Waiting for master to send event\n                  Master_Host: 192.168.168.146\n                  <strong>Master_User: slave<\/strong>\n                  Master_Port: 3306\n                Connect_Retry: 10\n              Master_Log_File: mysql-index.000001\n          Read_Master_Log_Pos: 699\n               Relay_Log_File: mariadb-relay-bin.000002\n                Relay_Log_Pos: 985\n        Relay_Master_Log_File: mysql-index.000001\n <strong>            Slave_IO_Running: Yes\n            Slave_SQL_Running: Yes<\/strong>\n              Replicate_Do_DB: <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u8bfb\u5199\u5206\u79bb\u7684\u5b9e\u73b0<\/h2>\n\n\n\n<p>         \u4f7f\u7528mycat\u4ee3\u7406\u65b9\u5f0f\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb\uff0cmycat\u7684\u5b89\u88c5\u9700\u8981jdk\u73af\u5883\u3002mycat\u7684\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6server.xml,schema.xml\u4e24\u4e2a\uff0c\u5177\u4f53\u914d\u7f6e\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server.xml\u7684\u914d\u7f6e\u4e3b\u8981\u662f\u5173\u4e8e\u524d\u7aef\u8fde\u63a5mycat\u7684\u7528\u6237\u540d\u5bc6\u7801\u3001ACL\u7b49\u4fe1\u606f\u7684\u4fee\u6539\uff0c\u6839\u636e\u9700\u8981\u4fee\u6539\u5373\u53ef\u3002\n\nschema.xml\u6587\u4ef6\u7684\u4e3b\u8981\u5185\u5bb9\u4e3amycat\u8fde\u63a5\u540e\u7aef\u6570\u636e\u5e93\u7684\u5730\u5740\u7aef\u53e3\u53ca\u7528\u6237\u540d\u5bc6\u7801\u7b49\u4fe1\u606f\u7684\u8bbe\u7f6e\u3002\n\ncat \/usr\/local\/mycat\/conf\/schema.xml\n\n&lt;?xml version=\"1.0\"?>\n&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n    &lt;schema name=\"TESTDB\" checkSQLschema=\"false\"  sqlMaxLimit=\"100\" dataNode=\"dn1\">\n    &lt;\/schema>\n    &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"student\" \/>\n    &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                      writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n            &lt;heartbeat>select user()&lt;\/heartbeat>\n            &lt;writeHost host=\"hostM1\" url=\"192.168.168.143:3306\" user=\"aaa\"\n                               password=\"123456\">\n                    &lt;readHost host=\"hostS1\" url=\"192.168.168.142:3306\" user=\"aaa\" password=\"123456\" \/>\n            &lt;\/writeHost>\n    &lt;\/dataHost>\n&lt;\/mycat:schema><\/code><\/pre>\n\n\n\n<p>\u542f\u52a8mycat\u670d\u52a1\uff0c\u5e76\u67e5\u770bmycat\u7684\u8fd0\u884c\u72b6\u6001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001\u5148\u4f7f\u7528\u8c03\u8bd5\u6a21\u5f0f\u8fd0\u884c\u68c0\u67e5\u662f\u5426\u6709\u9519\uff0c\u6700\u540e\u4e00\u884c\u663e\u793a<strong>successfully<\/strong>\u8868\u793a\u8fd0\u884c\u6b63\u786e\u3002\n\n&#91;root@localhost ~]# \/usr\/local\/mycat\/bin\/mycat console\nRunning Mycat-server...\nwrapper  | --> Wrapper Started as Console\nwrapper  | Launching a JVM...\njvm 1    | OpenJDK 64-Bit Server VM warning: Option AggressiveOpts was deprecated in version 11.0 and will likely be removed in a future release.\njvm 1    | Wrapper (Version 3.2.3) http:\/\/wrapper.tanukisoftware.org\njvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.\njvm 1    | \njvm 1    | MyCAT Server startup <strong>successfully<\/strong>. see logs in logs\/mycat.log\n\n2\u3001\u505c\u6b62\u8c03\u8bd5\u6a21\u5f0f\uff0c\u542f\u52a8mycat\n\ncontrol+c\n\n&#91;root@localhost ~]# \/usr\/local\/mycat\/bin\/mycat start\nStarting Mycat-server...\n&#91;root@localhost ~]# \n\n3\u3001\u67e5\u770b\u8fd0\u884c\u60c5\u51b5\n\nRS_CODE = 1 \u8868\u793a\u8fde\u63a5\u6570\u636e\u5e93\u6c60\u6b63\u5e38\u3002\n\n&#91;root@localhost ~]# mysql -h127.0.0.1 -uroot -p -P9066<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"152\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2024\/12\/image-4-1024x152.png\" alt=\"\" class=\"wp-image-563\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-4-1024x152.png 1024w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-4-300x44.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-4-768x114.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-4-816x121.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-4.png 1147w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<p>1\u3001mycat\u7684\u914d\u7f6e\u6587\u4ef6\u6709\u9519\u7684\u60c5\u51b5\u4e0b\uff0c\u63d0\u793a\u5e76\u4e0d\u662f\u5f88\u6e05\u6670\uff0c\u9700\u8981\u4ed4\u7ec6\u6392\u67e5\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e3b\u4ece\u590d\u5236\u7684\u5b9e\u73b0 \u5b89\u88c5mysql\u6570\u636e\u5e93\u4e00\u4e3b\u4e8c\u4ece\u5171\u4e09\u53f0 \u4e8c\u3001\u8bfb\u5199\u5206\u79bb\u7684\u5b9e\u73b0 \u4f7f\u7528mycat\u4ee3\u7406\u65b9\u5f0f\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[20,36,35],"tags":[108,109,86],"class_list":["post-553","post","type-post","status-publish","format-aside","hentry","category-linux","category-36","category-35","tag-mariadb","tag-mycat","tag-86","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=553"}],"version-history":[{"count":11,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":811,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions\/811"}],"wp:attachment":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}