{"id":843,"date":"2024-06-05T20:36:11","date_gmt":"2024-06-05T12:36:11","guid":{"rendered":"https:\/\/cn.raksmart.com\/blog\/host\/4201.html"},"modified":"2024-06-05T20:36:11","modified_gmt":"2024-06-05T12:36:11","slug":"mysql%e9%83%a8%e7%bd%b2%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/cn.raksmart.com\/blog\/knowledge\/843.html","title":{"rendered":"MySQL\u90e8\u7f72\u8fc7\u7a0b"},"content":{"rendered":"<div class=\"entry-content e-content\" itemprop=\"description articleBody\">\n<p>\u672c\u6587Raksmart\u4e3b\u8981\u5c31\u5982\u4f55\u5728<strong><a href=\"https:\/\/cn.raksmart.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"\u72ec\u7acb\u670d\u52a1\u5668\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">\u72ec\u7acb\u670d\u52a1\u5668<\/a><\/strong>\u4e0a\u90e8\u7f72<a href=\"https:\/\/www.raksmart.com\/cps\/7921\" target=\"_blank\" rel=\"noopener\">MySQL<\/a>\u505a\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5185\u5bb9\u53ca\u6b65\u9aa4\u4ec5\u4f9b\u53c2\u8003\u3002<\/p>\n<p class=\"has-text-color has-vivid-red-color\">\u4e00\u3001\u4fdd\u8bc1Master\u5e93\u548cSlave\u5e93\u7684\u6570\u636e\u548c\u7ed3\u6784\u4e00\u81f4<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7<a href=\"https:\/\/www.raksmart.com\/cps\/7921\" target=\"_blank\" rel=\"noopener\">mysql<\/a>dump\u6216\u8005XtraBackup\u5de5\u5177\u5bf9Master\u5e93\u8fdb\u884c\u5168\u5907\uff0c\u518d\u628a\u5907\u4efd\u6587\u4ef6\u4f20\u5230Slave\u5e93\uff0cSlave\u5e93\u5229\u7528\u6539\u5907\u4efd\u8fdb\u884c\u6062\u590d\uff0c\u4f7f\u5f97\u4e24\u8005\u4e00\u81f4\u3002<\/p>\n<p>\u6211\u8fd9\u91cc\u7684Slave\u5e93\u662f\u76f4\u63a5\u590d\u5236Master\u5e93\u751f\u6210\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u505a\u8fd9\u4e00\u6b65\u4e86\u3002<\/p>\n<p class=\"has-text-color has-vivid-red-color\">\u4e8c\u3001\u914d\u7f6e\u4e24\u4e2a\u5e93\u7684\u53c2\u6570\u6587\u4ef6<\/p>\n<p>Master\u5e93\u9700\u8981\u6253\u5f00\u4e8c\u8fdb\u5236\u65e5\u5fd7<\/p>\n<p>Master\u5e93\u9700\u8981\u8bbe\u7f6e\u4e0eSlave\u5e93\u4e0d\u540c\u7684server-id<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>\uff3broot@potato data\uff3dvi \/etc\/my.cnf<\/p>\n<p>binlog_format = mixed<\/p>\n<p>server-id = 203306<\/p>\n<p>log-bin = mybinlog<\/p>\n<p>Slave\u5e93\u53ea\u9700\u914d\u7f6eserver-id\u5373\u53ef<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>\uff3broot@tomato data\uff3dvi \/etc\/my.cnf<\/p>\n<p>server-id = 203307<\/p>\n<p class=\"has-text-color has-vivid-red-color\">\u4e09\u3001\u521b\u5efa\u7528\u6765\u8fdb\u884c\u590d\u5236\u7684\u7528\u6237\u5e76\u4e14\u8d4b\u6743<\/p>\n<p>\u5fc5\u987b\u7ed9\u4e88\u7528\u6237replication slave\u6743\u9650\uff0c\u6307\u5b9aSlave\u5e93\u7684\u4e3b\u673a\u5730\u5740<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 05:02:32 \uff3b\uff08none\uff09\uff3d\u300bgrant replication slave on *.* to<br \/>\nrepl@\u2018192.168.161.128\u2019 identified by \u2018repl\u2019;<\/p>\n<p class=\"has-text-color has-vivid-red-color\">\u56db\u3001\u8ba9Slave\u5e93change\u5230Master\u5e93<\/p>\n<p>\u67e5\u770bMaster\u5e93\u6b64\u65f6\u7684\u65e5\u5fd7\u4f4d\u7f6e<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 05:02:32 \uff3b\uff08none\uff09\uff3d\u300bshow master status ;<\/p>\n<p>+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014-+\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2014\u2014\u2014-+<\/p>\n<p>| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |<\/p>\n<p>+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014-+\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2014\u2014\u2014-+<\/p>\n<p>| mybinlog.000004 | 331 | | | |<\/p>\n<p>+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014-+\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2014\u2014\u2014-+<\/p>\n<p>1 row in set \uff080.00 sec\uff09<\/p>\n<p>\u4ece\u5e93\u5f00\u59cbchange\u5230master\u5e93\u4e0a<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 04:29:15 \uff3b\uff08none\uff09\uff3d\u300bchange master to<\/p>\n<p>-\u300b master_host=\u2018192.168.161.128\u2019\uff0c<\/p>\n<p>-\u300b master_port=3306\uff0c<\/p>\n<p>-\u300b master_user=\u2018repl\u2019\uff0c<\/p>\n<p>-\u300b master_password=\u2018repl\u2019\uff0c<\/p>\n<p>-\u300b master_log_file=\u2018mybinlog.000004\u2019\uff0c<\/p>\n<p>-\u300b master_log_pos=331;<\/p>\n<p>ERROR 2006 \uff08HY000\uff09\uff1a MySQL server has gone away<\/p>\n<p>No connection. Trying to reconnect.\u3002.<\/p>\n<p>Connection id\uff1a 2<\/p>\n<p>Current database\uff1a *** NONE ***<\/p>\n<p>Query OK\uff0c 0 rows affected\uff0c 2 warnings \uff080.17 sec\uff09<\/p>\n<p class=\"has-text-color has-vivid-red-color\">\u4e94\u3001Slave\u5e93\u6267\u884c\u5f00\u59cb\u590d\u5236\u547d\u4ee4<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 04:40:11 \uff3b\uff08none\uff09\uff3d\u300bstart slave;<\/p>\n<p>\u5230\u6b64\uff0c\u4e3b\u4ece\u590d\u5236\u5c31\u5df2\u7ecf\u914d\u7f6e\u5b8c\u6bd5\u4e86<\/p>\n<p class=\"has-text-color has-vivid-red-color\">\u516d\u3001\u5bf9\u642d\u5efa\u7684\u73af\u5883\u8fdb\u884c\u6d4b\u8bd5\u6d4b\u8bd5<\/p>\n<p>\u4e3b\u5e93\u5f00\u59cb\u63d2\u5165\u6570\u636e\u6d4b\u8bd5<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 04:40:11 \uff3b\uff08none\uff09\uff3d\u300buse lala;<\/p>\n<p>root@localhost:mysql.sock 04:51:23 \uff3b\uff08lala\uff09\uff3d\u300bcreate table haha\uff08id int\uff09;<\/p>\n<p>root@localhost:mysql.sock 04:51:23 \uff3b\uff08lala\uff09\uff3d\u300binsert into haha values\uff081\uff09;<\/p>\n<p>\u4ece\u5e93\u662f\u5426\u63a5\u53d7\u5230\u6570\u636e<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 04:52:55 \uff3b\uff08none\uff09\uff3d\u300bselect * from lala.haha;<\/p>\n<p>+\u2014\u2014+<\/p>\n<p>| id |<\/p>\n<p>+\u2014\u2014+<\/p>\n<p>| 1 |<\/p>\n<p>+\u2014\u2014+<\/p>\n<p>1 row in set \uff080.00 sec\uff09<\/p>\n<p>\u67e5\u770bSlave\u72b6\u6001<\/p>\n<p>\u70b9\u51fb\uff08\u6b64\u5904\uff09\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<p>root@localhost:mysql.sock 04:57:23 \uff3b\uff08none\uff09\uff3d\u300bshow slave statusG<\/p>\n<p>*************************** 1. row ***************************<\/p>\n<p>Slave_IO_State\uff1a Waiting for master to send event<\/p>\n<p>Master_Host\uff1a 192.168.161.128<\/p>\n<p>Master_User\uff1a repl<\/p>\n<p>Master_Port\uff1a 3306<\/p>\n<p>Connect_Retry\uff1a 60<\/p>\n<p>Master_Log_File\uff1a mybinlog.000004<\/p>\n<p>Read_Master_Log_Pos\uff1a 620<\/p>\n<p>Relay_Log_File\uff1a mysql-relay-bin.000003<\/p>\n<p>Relay_Log_Pos\uff1a 571<\/p>\n<p>Relay_Master_Log_File\uff1a mybinlog.000004<\/p>\n<p>Slave_IO_Running\uff1a Yes<\/p>\n<p>Slave_SQL_Running\uff1a Yes<\/p>\n<p>Replicate_Do_DB\uff1a<\/p>\n<p>Replicate_Ignore_DB\uff1a<\/p>\n<p>Replicate_Do_Table\uff1a<\/p>\n<p>Replicate_Ignore_Table\uff1a<\/p>\n<p>Replicate_Wild_Do_Table\uff1a<\/p>\n<p>Replicate_Wild_Ignore_Table\uff1a<\/p>\n<p>Last_Errno\uff1a 0<\/p>\n<p>Last_Error\uff1a<\/p>\n<p>Skip_Counter\uff1a 0<\/p>\n<p>Exec_Master_Log_Pos\uff1a 620<\/p>\n<p>Relay_Log_Space\uff1a 744<\/p>\n<p>Until_Condition\uff1a None<\/p>\n<p>Until_Log_File\uff1a<\/p>\n<p>Until_Log_Pos\uff1a 0<\/p>\n<p>Master_SSL_Allowed\uff1a No<\/p>\n<p>Master_SSL_CA_File\uff1a<\/p>\n<p>Master_SSL_CA_Path\uff1a<\/p>\n<p>Master_SSL_Cert\uff1a<\/p>\n<p>Master_SSL_Cipher\uff1a<\/p>\n<p>Master_SSL_Key\uff1a<\/p>\n<p>Seconds_Behind_Master\uff1a 0<\/p>\n<p>Master_SSL_Verify_Server_Cert\uff1a No<\/p>\n<p>Last_IO_Errno\uff1a 0<\/p>\n<p>Last_IO_Error\uff1a<\/p>\n<p>Last_SQL_Errno\uff1a 0<\/p>\n<p>Last_SQL_Error\uff1a<\/p>\n<p>Replicate_Ignore_Server_Ids\uff1a<\/p>\n<p>Master_Server_Id\uff1a 203306<\/p>\n<p>Master_UUID\uff1a af3609cd-b426-11e6-a997-000c29d55626<\/p>\n<p>Master_Info_File\uff1a \/data\/mysql\/mytest_3306\/data\/master.info<\/p>\n<p>SQL_Delay\uff1a 0<\/p>\n<p>SQL_Remaining_Delay\uff1a NULL<\/p>\n<p>Slave_SQL_Running_State\uff1a Slave has read all relay log; waiting for the slave<br \/>\nI\/O thread to update it<\/p>\n<p>Master_Retry_Count\uff1a 86400<\/p>\n<p>Master_Bind\uff1a<\/p>\n<p>Last_IO_Error_Timestamp\uff1a<\/p>\n<p>Last_SQL_Error_Timestamp\uff1a<\/p>\n<p>Master_SSL_Crl\uff1a<\/p>\n<p>Master_SSL_Crlpath\uff1a<\/p>\n<p>Retrieved_Gtid_Set\uff1a<\/p>\n<p>Executed_Gtid_Set\uff1a<\/p>\n<p>Auto_Position\uff1a 0<\/p>\n<p>1 row in set \uff080.00 sec\uff09<\/p>\n<p>\u4e3b\u4ece\u590d\u5236\u90e8\u7f72\u6d4b\u8bd5\u6210\u529f\uff0c\u63a8\u8350\u76f8\u5173\u5185\u5bb9\uff0c<a href=\"https:\/\/cn.raksmart.com\/blog\/server\/723.html\">\u5982\u4f55\u8fd0\u884c\u4e0e\u5173\u95edMySQL\u670d\u52a1\u5668<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587Raksmart\u4e3b\u8981\u5c31\u5982\u4f55\u5728\u72ec\u7acb\u670d\u52a1\u5668\u4e0a\u90e8\u7f72MySQL\u505a\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5185\u5bb9\u53ca\u6b65\u9aa4\u4ec5\u4f9b\u53c2\u8003\u3002 \u4e00\u3001\u4fdd\u8bc1\u2026 <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[684,35],"class_list":["post-843","post","type-post","status-publish","format-standard","hentry","category-knowledge","tag-mysql","tag-35"],"_links":{"self":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts\/843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/comments?post=843"}],"version-history":[{"count":0,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts\/843\/revisions"}],"wp:attachment":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/media?parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/categories?post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/tags?post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}