{"id":65990,"date":"2026-01-26T01:56:46","date_gmt":"2026-01-25T17:56:46","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/65990.html"},"modified":"2026-01-26T01:56:46","modified_gmt":"2026-01-25T17:56:46","slug":"%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3mysql%e6%97%a5%e5%bf%97%e7%9a%84%e5%85%ad%e5%a4%a7%e6%a0%b8%e5%bf%83%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/65990.html","title":{"rendered":"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b"},"content":{"rendered":"<h2>MySQL \u65e5\u5fd7\u4f53\u7cfb&#xff1a;\u5206\u7c7b\u3001\u4f7f\u7528\u573a\u666f\u4e0e\u5b9e\u6218\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>MySQL \u7684\u65e5\u5fd7\u4f53\u7cfb\u662f\u5176\u9ad8\u53ef\u7528\u3001\u53ef\u6062\u590d\u3001\u53ef\u76d1\u63a7\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u4e0d\u540c\u65e5\u5fd7\u627f\u62c5\u7740\u6545\u969c\u6062\u590d\u3001\u6570\u636e\u5ba1\u8ba1\u3001\u6027\u80fd\u8c03\u4f18\u3001\u4e3b\u4ece\u540c\u6b65\u7b49\u4e0d\u540c\u6838\u5fc3\u804c\u8d23\u3002\u4f5c\u4e3a\u540e\u7aef\u5f00\u53d1\u548c DBA \u65e5\u5e38\u5de5\u4f5c\u4e2d\u9ad8\u9891\u63a5\u89e6\u7684\u6838\u5fc3\u7ec4\u4ef6&#xff0c;\u638c\u63e1\u5404\u7c7b\u65e5\u5fd7\u7684\u7279\u6027\u3001\u4f7f\u7528\u573a\u666f\u53ca\u95ee\u9898\u89e3\u51b3\u65b9\u6848&#xff0c;\u662f\u4fdd\u969c MySQL \u670d\u52a1\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002\u672c\u6587\u5c06\u4ece MySQL \u6838\u5fc3\u65e5\u5fd7\u5206\u7c7b\u51fa\u53d1&#xff0c;\u9010\u4e00\u8bb2\u89e3\u5176\u539f\u7406\u3001\u9002\u7528\u573a\u666f&#xff0c;\u5e76\u7ed3\u5408\u5b9e\u9645\u751f\u4ea7\u573a\u666f\u7ed9\u51fa\u914d\u7f6e\u3001\u6392\u67e5\u3001\u4f18\u5316\u7684\u5b9e\u6218\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<h3>\u4e00\u3001MySQL \u6838\u5fc3\u65e5\u5fd7\u5206\u7c7b\u4e0e\u57fa\u7840\u539f\u7406<\/h3>\n<p>MySQL \u7684\u65e5\u5fd7\u4f53\u7cfb\u6309\u529f\u80fd\u53ef\u5206\u4e3a\u4e8b\u52a1\u65e5\u5fd7\u3001\u67e5\u8be2\u65e5\u5fd7\u3001\u9519\u8bef\u65e5\u5fd7\u3001\u4e8c\u8fdb\u5236\u65e5\u5fd7\u3001\u4e2d\u7ee7\u65e5\u5fd7\u3001\u6162\u67e5\u8be2\u65e5\u5fd7\u516d\u5927\u6838\u5fc3\u7c7b\u578b&#xff0c;\u5176\u4e2dredo log&#xff08;\u91cd\u505a\u65e5\u5fd7&#xff09; \u3001undo log&#xff08;\u56de\u6eda\u65e5\u5fd7&#xff09; \u4f5c\u4e3a\u4e8b\u52a1\u65e5\u5fd7&#xff0c;\u662f\u4fdd\u969c\u4e8b\u52a1 ACID \u7279\u6027\u7684\u5e95\u5c42\u6838\u5fc3&#xff1b;binlog&#xff08;\u4e8c\u8fdb\u5236\u65e5\u5fd7&#xff09; \u662f\u4e3b\u4ece\u540c\u6b65\u548c\u6570\u636e\u6062\u590d\u7684\u5173\u952e&#xff1b;\u6162\u67e5\u8be2\u65e5\u5fd7\u5219\u662f\u6027\u80fd\u8c03\u4f18\u7684\u6838\u5fc3\u5de5\u5177\u3002<\/p>\n<p>\u4e0d\u540c\u65e5\u5fd7\u7684\u5b58\u50a8\u5f62\u5f0f\u3001\u5f00\u542f\u65b9\u5f0f\u5dee\u5f02\u8f83\u5927&#xff0c;\u90e8\u5206\u65e5\u5fd7&#xff08;\u5982 redo log\u3001undo log&#xff09;\u4e3a MySQL \u9ed8\u8ba4\u5f00\u542f\u7684\u5e95\u5c42\u65e5\u5fd7&#xff0c;\u65e0\u9700\u624b\u52a8\u914d\u7f6e&#xff1b;\u90e8\u5206\u65e5\u5fd7&#xff08;\u5982\u6162\u67e5\u8be2\u65e5\u5fd7\u3001\u901a\u7528\u67e5\u8be2\u65e5\u5fd7&#xff09;\u9700\u624b\u52a8\u5f00\u542f\u5e76\u914d\u7f6e\u53c2\u6570&#xff1b;\u8fd8\u6709\u90e8\u5206\u65e5\u5fd7&#xff08;\u5982\u4e2d\u7ee7\u65e5\u5fd7&#xff09;\u4e3a\u4ece\u5e93\u4e13\u5c5e&#xff0c;\u4e3b\u5e93\u65e0\u9700\u914d\u7f6e\u3002<\/p>\n<h3>\u4e8c\u3001\u5404\u6838\u5fc3\u65e5\u5fd7\u8be6\u89e3&#xff1a;\u539f\u7406\u3001\u4f7f\u7528\u573a\u666f\u4e0e\u914d\u7f6e<\/h3>\n<h4>&#xff08;\u4e00&#xff09;\u4e8b\u52a1\u65e5\u5fd7&#xff1a;redo log &#043; undo log&#xff08;\u4fdd\u969c\u4e8b\u52a1 ACID&#xff09;<\/h4>\n<p>\u4e8b\u52a1\u65e5\u5fd7\u662f MySQL InnoDB \u5b58\u50a8\u5f15\u64ce\u72ec\u6709\u7684\u65e5\u5fd7&#xff08;MyISAM \u65e0\u4e8b\u52a1\u65e5\u5fd7&#xff0c;\u4e0d\u652f\u6301\u4e8b\u52a1&#xff09;&#xff0c;\u662f\u5b9e\u73b0\u4e8b\u52a1\u539f\u5b50\u6027\u3001\u4e00\u81f4\u6027\u3001\u6301\u4e45\u6027\u7684\u6838\u5fc3&#xff0c;\u4e5f\u662f\u89e3\u51b3 MySQL \u201c\u968f\u673a\u5199\u201d \u8f6c \u201c\u987a\u5e8f\u5199\u201d\u3001\u63d0\u5347\u5199\u5165\u6027\u80fd\u7684\u5173\u952e\u3002<\/p>\n<h5>1. redo log&#xff08;\u91cd\u505a\u65e5\u5fd7&#xff09;<\/h5>\n<p>\u6838\u5fc3\u539f\u7406&#xff1a;InnoDB \u4e3a\u4e86\u89e3\u51b3\u78c1\u76d8\u968f\u673a\u5199\u7684\u6027\u80fd\u95ee\u9898&#xff0c;\u5f15\u5165\u4e86\u7f13\u51b2\u6c60&#xff08;Buffer Pool&#xff09;&#xff0c;\u6570\u636e\u4fee\u6539\u5148\u5199\u5165 Buffer Pool \u548c redo log&#xff08;\u987a\u5e8f\u5199&#xff09;&#xff0c;\u518d\u7531\u540e\u53f0\u7ebf\u7a0b&#xff08;master thread&#xff09;\u5f02\u6b65\u5237\u76d8\u5230\u78c1\u76d8\u6570\u636e\u6587\u4ef6\u3002redo log \u662f\u7269\u7406\u65e5\u5fd7&#xff0c;\u8bb0\u5f55\u7684\u662f \u201c\u67d0\u4e2a\u6570\u636e\u9875\u7684\u67d0\u4e2a\u4f4d\u7f6e\u505a\u4e86\u4ec0\u4e48\u4fee\u6539\u201d&#xff0c;\u5177\u6709\u5faa\u73af\u5199\u7279\u6027&#xff08;\u56fa\u5b9a\u5927\u5c0f\u7684\u6587\u4ef6\u7ec4&#xff0c;\u5199\u6ee1\u540e\u8986\u76d6\u65e7\u65e5\u5fd7&#xff09;\u3002\u6838\u5fc3\u4f5c\u7528&#xff1a;\u4fdd\u969c\u4e8b\u52a1\u7684\u6301\u4e45\u6027&#xff08;Durability&#xff09;&#xff0c;\u5373\u4f7f\u6570\u636e\u5e93\u5d29\u6e83&#xff0c;\u91cd\u542f\u540e\u53ef\u901a\u8fc7 redo log \u6062\u590d\u672a\u5237\u76d8\u7684\u4fee\u6539&#xff0c;\u907f\u514d\u6570\u636e\u4e22\u5931\u3002\u4f7f\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u6570\u636e\u5e93\u5f02\u5e38\u5d29\u6e83\u540e\u7684\u6570\u636e\u6062\u590d&#xff0c;\u662f MySQL \u6700\u57fa\u7840\u7684\u6545\u969c\u6062\u590d\u624b\u6bb5&#xff1b;<\/li>\n<li>\u6240\u6709 InnoDB \u4e8b\u52a1\u7684\u5199\u5165\u64cd\u4f5c&#xff0c;\u5e95\u5c42\u5747\u4f9d\u8d56 redo log \u63d0\u5347\u6027\u80fd\u3002\u5173\u952e\u914d\u7f6e&#xff08;\u65e0\u9700\u624b\u52a8\u5f00\u542f&#xff0c;\u9ed8\u8ba4\u5f00\u542f&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p># redo log\u6587\u4ef6\u7ec4\u7684\u5927\u5c0f&#xff0c;\u9ed8\u8ba448M&#xff0c;\u751f\u4ea7\u5efa\u8bae\u8bbe\u7f6e\u4e3a1-2G&#xff0c;\u591a\u4e2a\u6587\u4ef6\u7528\u9017\u53f7\u5206\u9694<br \/>\ninnodb_log_file_size &#061; 1G<br \/>\n# redo log\u6587\u4ef6\u7684\u6570\u91cf&#xff0c;\u9ed8\u8ba42\u4e2a<br \/>\ninnodb_log_files_in_group &#061; 2<br \/>\n# redo log\u6587\u4ef6\u7684\u5b58\u50a8\u8def\u5f84&#xff0c;\u9ed8\u8ba4\u4e0e\u6570\u636e\u6587\u4ef6\u540c\u76ee\u5f55<br \/>\ninnodb_log_group_home_dir &#061; \/var\/lib\/mysql\/<br \/>\n# \u5237\u76d8\u7b56\u7565&#xff0c;\u751f\u4ea7\u5efa\u8bae1&#xff08;\u4e8b\u52a1\u63d0\u4ea4\u65f6\u5237\u76d8&#xff0c;\u517c\u987e\u6027\u80fd\u548c\u6301\u4e45\u6027&#xff09;<br \/>\ninnodb_flush_log_at_trx_commit &#061; 1<\/p>\n<p>\u6838\u5fc3\u7279\u6027&#xff1a;\u5faa\u73af\u5199\u3001\u7269\u7406\u65e5\u5fd7\u3001\u987a\u5e8f IO&#xff0c;\u6027\u80fd\u8fdc\u9ad8\u4e8e\u78c1\u76d8\u968f\u673a\u5199\u3002<\/p>\n<h5>2. undo log&#xff08;\u56de\u6eda\u65e5\u5fd7&#xff09;<\/h5>\n<p>\u6838\u5fc3\u539f\u7406&#xff1a;undo log \u662f\u903b\u8f91\u65e5\u5fd7&#xff0c;\u8bb0\u5f55\u7684\u662f \u201c\u6570\u636e\u4fee\u6539\u524d\u7684\u72b6\u6001\u201d&#xff08;\u5982\u63d2\u5165\u4e00\u6761\u6570\u636e\u5219\u8bb0\u5f55\u5220\u9664\u8be5\u6570\u636e&#xff0c;\u66f4\u65b0\u4e00\u6761\u6570\u636e\u5219\u8bb0\u5f55\u6062\u590d\u539f\u6570\u636e&#xff09;&#xff0c;\u5b58\u50a8\u5728 InnoDB \u7684\u56de\u6eda\u6bb5\u4e2d\u3002\u6838\u5fc3\u4f5c\u7528&#xff1a;<\/p>\n<ul>\n<li>\u4fdd\u969c\u4e8b\u52a1\u7684\u539f\u5b50\u6027&#xff08;Atomicity&#xff09;&#xff0c;\u4e8b\u52a1\u6267\u884c\u5931\u8d25\u65f6&#xff0c;\u901a\u8fc7 undo log \u56de\u6eda\u5230\u4e8b\u52a1\u6267\u884c\u524d\u7684\u72b6\u6001&#xff1b;<\/li>\n<li>\u5b9e\u73b0\u884c\u7ea7\u9501\u7684\u91ca\u653e&#xff08;InnoDB \u884c\u9501\u57fa\u4e8e undo log \u5b9e\u73b0\u5e7b\u8bfb\u89e3\u51b3&#xff09;&#xff1b;<\/li>\n<li>\u652f\u6301MVCC&#xff08;\u591a\u7248\u672c\u5e76\u53d1\u63a7\u5236&#xff09; &#xff0c;\u8bfb\u64cd\u4f5c\u901a\u8fc7 undo log \u8bfb\u53d6\u6570\u636e\u7684\u5386\u53f2\u7248\u672c&#xff0c;\u5b9e\u73b0\u65e0\u9501\u8bfb\u3002\u4f7f\u7528\u573a\u666f&#xff1a;<\/li>\n<li>\u4e8b\u52a1\u6267\u884c\u5f02\u5e38\u65f6\u7684\u624b\u52a8\u56de\u6eda&#xff08;rollback&#xff09;\u548c\u81ea\u52a8\u56de\u6eda&#xff1b;<\/li>\n<li>\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684 MVCC \u65e0\u9501\u8bfb&#xff0c;\u63d0\u5347\u8bfb\u6027\u80fd&#xff1b;<\/li>\n<li>\u884c\u7ea7\u9501\u7684\u5e95\u5c42\u652f\u6491&#xff0c;\u907f\u514d\u9501\u7ade\u4e89\u5bfc\u81f4\u7684\u6027\u80fd\u95ee\u9898\u3002\u5173\u952e\u914d\u7f6e&#xff08;\u9ed8\u8ba4\u5f00\u542f&#xff0c;\u91cd\u70b9\u914d\u7f6e\u56de\u6eda\u6bb5\u548c\u7a7a\u95f4&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p># \u5f00\u542f\u72ec\u7acb\u7684undo\u8868\u7a7a\u95f4&#xff0c;\u5efa\u8bae\u5f00\u542f&#xff0c;\u65b9\u4fbf\u7ba1\u7406\u548c\u6e05\u7406<br \/>\ninnodb_undo_tablespace &#061; 3<br \/>\n# \u56de\u6eda\u6bb5\u7684\u6570\u91cf&#xff0c;\u751f\u4ea7\u5efa\u8bae128&#xff0c;\u63d0\u5347\u5e76\u53d1\u4e8b\u52a1\u5904\u7406\u80fd\u529b<br \/>\ninnodb_rollback_segments &#061; 128<br \/>\n# \u81ea\u52a8\u6e05\u7406\u8fc7\u671f\u7684undo log&#xff0c;\u9ed8\u8ba4\u5f00\u542f<br \/>\ninnodb_undo_log_truncate &#061; ON<br \/>\n# \u89e6\u53d1undo log\u6e05\u7406\u7684\u9608\u503c&#xff0c;\u9ed8\u8ba41G<br \/>\ninnodb_purge_rseg_truncate_frequency &#061; 128<\/p>\n<p>\u6838\u5fc3\u7279\u6027&#xff1a;\u903b\u8f91\u65e5\u5fd7\u3001\u53ef\u56de\u6eda\u3001\u652f\u6301\u591a\u7248\u672c&#xff0c;\u968f\u4e8b\u52a1\u63d0\u4ea4\u540e\u9010\u6b65\u7531\u540e\u53f0\u7ebf\u7a0b\u6e05\u7406\u3002<\/p>\n<h4>&#xff08;\u4e8c&#xff09;\u4e8c\u8fdb\u5236\u65e5\u5fd7&#xff1a;binlog&#xff08;\u4e3b\u4ece\u540c\u6b65 &#043; \u6570\u636e\u6062\u590d\u6838\u5fc3&#xff09;<\/h4>\n<p>binlog \u662f MySQL\u670d\u52a1\u5668\u5c42\u7684\u65e5\u5fd7&#xff08;\u6240\u6709\u5b58\u50a8\u5f15\u64ce\u5747\u652f\u6301&#xff09;&#xff0c;\u662f MySQL \u751f\u6001\u4e2d\u6700\u6838\u5fc3\u7684\u65e5\u5fd7\u4e4b\u4e00&#xff0c;\u4e0e InnoDB \u7684 redo log \u5f62\u6210\u4e92\u8865&#xff08;redo log \u662f\u5f15\u64ce\u5c42\u7269\u7406\u65e5\u5fd7&#xff0c;binlog \u662f\u670d\u52a1\u5668\u5c42\u903b\u8f91\u65e5\u5fd7&#xff09;\u3002<\/p>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>binlog \u8bb0\u5f55\u4e86 MySQL \u4e2d\u6240\u6709\u5bf9\u6570\u636e\u4ea7\u751f\u4fee\u6539\u7684\u64cd\u4f5c&#xff08;\u589e\u5220\u6539&#xff0c;\u67e5\u64cd\u4f5c\u4e0d\u8bb0\u5f55&#xff09;&#xff0c;\u4ee5\u4e8c\u8fdb\u5236\u683c\u5f0f\u5b58\u50a8&#xff0c;\u5206\u4e3a\u8bed\u53e5\u7ea7&#xff08;Statement&#xff09; \u3001\u884c\u7ea7&#xff08;Row&#xff09; \u3001\u6df7\u5408\u7ea7&#xff08;Mixed&#xff09; \u4e09\u79cd\u683c\u5f0f&#xff0c;\u5177\u6709\u8ffd\u52a0\u5199\u7279\u6027&#xff08;\u5199\u6ee1\u4e00\u4e2a\u6587\u4ef6\u540e\u81ea\u52a8\u5207\u6362\u4e0b\u4e00\u4e2a&#xff0c;\u4e0d\u4f1a\u8986\u76d6&#xff09;\u3002<\/p>\n<ul>\n<li>Statement&#xff1a;\u8bb0\u5f55\u6267\u884c\u7684 SQL \u8bed\u53e5&#xff0c;\u65e5\u5fd7\u4f53\u79ef\u5c0f&#xff0c;\u4f46\u5b58\u5728\u4e3b\u4ece\u4e0d\u4e00\u81f4\u98ce\u9669&#xff08;\u5982\u4f7f\u7528 now ()\u3001rand () \u7b49\u51fd\u6570&#xff09;&#xff1b;<\/li>\n<li>Row&#xff1a;\u8bb0\u5f55\u6570\u636e\u7684\u4fee\u6539\u524d\u540e\u72b6\u6001&#xff0c;\u65e0\u4e3b\u4ece\u4e0d\u4e00\u81f4\u95ee\u9898&#xff0c;\u65e5\u5fd7\u4f53\u79ef\u7a0d\u5927&#xff0c;\u662f\u751f\u4ea7\u73af\u5883\u9996\u9009&#xff1b;<\/li>\n<li>Mixed&#xff1a;\u81ea\u52a8\u5207\u6362 Statement \u548c Row&#xff0c;\u7b80\u5355\u64cd\u4f5c\u7528 Statement&#xff0c;\u590d\u6742\u64cd\u4f5c\u7528 Row\u3002<\/li>\n<\/ul>\n<h5>\u6838\u5fc3\u4f5c\u7528<\/h5>\n<li>\u4e3b\u4ece\u590d\u5236&#xff1a;\u4e3b\u5e93\u5c06 binlog \u53d1\u9001\u7ed9\u4ece\u5e93&#xff0c;\u4ece\u5e93\u901a\u8fc7\u89e3\u6790 binlog \u6267\u884c\u76f8\u540c\u7684\u4fee\u6539&#xff0c;\u5b9e\u73b0\u4e3b\u4ece\u6570\u636e\u540c\u6b65&#xff1b;<\/li>\n<li>\u6570\u636e\u6062\u590d&#xff1a;\u901a\u8fc7 mysqlbinlog \u5de5\u5177\u89e3\u6790 binlog&#xff0c;\u91cd\u653e\u6307\u5b9a\u65f6\u95f4\u6bb5 \/ \u6307\u5b9a\u64cd\u4f5c\u7684 SQL&#xff0c;\u5b9e\u73b0\u6570\u636e\u7684\u65f6\u95f4\u70b9\u6062\u590d&#xff1b;<\/li>\n<li>\u6570\u636e\u5ba1\u8ba1&#xff1a;\u89e3\u6790 binlog \u53ef\u8ffd\u6eaf\u6240\u6709\u6570\u636e\u4fee\u6539\u64cd\u4f5c&#xff0c;\u5b9a\u4f4d\u6570\u636e\u53d8\u66f4\u7684\u6e90\u5934\u3002<\/li>\n<h5>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h5>\n<ul>\n<li>\u4e3b\u4ece\u590d\u5236\u3001\u4e3b\u4e3b\u590d\u5236\u7684\u6838\u5fc3\u4f9d\u8d56&#xff0c;\u662f\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u67b6\u6784\u7684\u57fa\u7840&#xff1b;<\/li>\n<li>\u6570\u636e\u8bef\u5220 \/ \u8bef\u6539\u540e\u7684\u7cbe\u51c6\u6062\u590d&#xff08;\u5982\u5220\u9664\u4e86\u4e00\u5f20\u8868&#xff0c;\u53ef\u901a\u8fc7 binlog \u6062\u590d\u5230\u5220\u9664\u524d\u7684\u72b6\u6001&#xff09;&#xff1b;<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u7684\u6570\u636e\u53d8\u66f4\u5ba1\u8ba1&#xff0c;\u6392\u67e5\u8c01\u5728\u4ec0\u4e48\u65f6\u95f4\u6267\u884c\u4e86\u4ec0\u4e48\u4fee\u6539\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h5>\u5173\u952e\u914d\u7f6e&#xff08;\u9ed8\u8ba4\u5173\u95ed&#xff0c;\u9700\u624b\u52a8\u5f00\u542f&#xff09;<\/h5>\n<p># \u5f00\u542fbinlog\u65e5\u5fd7<br \/>\nlog_bin &#061; ON<br \/>\n# binlog\u65e5\u5fd7\u7684\u5b58\u50a8\u8def\u5f84\u548c\u524d\u7f00&#xff0c;\u540e\u7eed\u4f1a\u751f\u6210mysql-bin.000001\u3001mysql-bin.000002\u7b49\u6587\u4ef6<br \/>\nlog_bin_basename &#061; \/var\/lib\/mysql\/mysql-bin<br \/>\n# binlog\u7d22\u5f15\u6587\u4ef6&#xff0c;\u8bb0\u5f55\u6240\u6709binlog\u6587\u4ef6\u7684\u540d\u79f0<br \/>\nlog_bin_index &#061; \/var\/lib\/mysql\/mysql-bin.index<br \/>\n# binlog\u683c\u5f0f&#xff0c;\u751f\u4ea7\u5efa\u8baeROW<br \/>\nbinlog_format &#061; ROW<br \/>\n# binlog\u8fc7\u671f\u6e05\u7406\u65f6\u95f4&#xff0c;\u9ed8\u8ba40&#xff08;\u4e0d\u6e05\u7406&#xff09;&#xff0c;\u751f\u4ea7\u5efa\u8bae7-15\u5929<br \/>\nexpire_logs_days &#061; 7<br \/>\n# \u6bcf\u4e2abinlog\u6587\u4ef6\u7684\u6700\u5927\u5927\u5c0f&#xff0c;\u9ed8\u8ba41G&#xff0c;\u751f\u4ea7\u5efa\u8bae1-2G<br \/>\nmax_binlog_size &#061; 1G<br \/>\n# \u4e8b\u52a1\u63d0\u4ea4\u65f6\u5237\u76d8\u7b56\u7565&#xff0c;\u751f\u4ea7\u5efa\u8bae1&#xff08;\u4fdd\u969c\u6301\u4e45\u6027&#xff09;<br \/>\nsync_binlog &#061; 1<\/p>\n<h5>\u6838\u5fc3\u64cd\u4f5c\u547d\u4ee4<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770bbinlog\u65e5\u5fd7\u5217\u8868<\/span><br \/>\n<span class=\"token keyword\">show<\/span> <span class=\"token keyword\">binary<\/span> logs<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">&#8212; \u67e5\u770b\u5f53\u524d\u6b63\u5728\u5199\u5165\u7684binlog\u6587\u4ef6<\/span><br \/>\n<span class=\"token keyword\">show<\/span> master <span class=\"token keyword\">status<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">&#8212; \u89e3\u6790binlog\u65e5\u5fd7&#xff08;\u7ec8\u7aef\u6267\u884c&#xff09;<\/span><br \/>\nmysqlbinlog <span class=\"token comment\">&#8211;no-defaults -v \/var\/lib\/mysql\/mysql-bin.000001<\/span><br \/>\n<span class=\"token comment\">&#8212; \u6309\u65f6\u95f4\u89e3\u6790binlog&#xff0c;\u5e76\u91cd\u5b9a\u5411\u5230sql\u6587\u4ef6&#xff08;\u7528\u4e8e\u6570\u636e\u6062\u590d&#xff09;<\/span><br \/>\nmysqlbinlog <span class=\"token comment\">&#8211;no-defaults -v &#8211;start-datetime&#061;&#034;2026-01-01 00:00:00&#034; &#8211;stop-datetime&#061;&#034;2026-01-01 12:00:00&#034; \/var\/lib\/mysql\/mysql-bin.000001 &gt; recover.sql<\/span><\/p>\n<h4>&#xff08;\u4e09&#xff09;\u6162\u67e5\u8be2\u65e5\u5fd7&#xff1a;slow query log&#xff08;\u6027\u80fd\u8c03\u4f18\u6838\u5fc3&#xff09;<\/h4>\n<p>\u6162\u67e5\u8be2\u65e5\u5fd7\u662f MySQL \u670d\u52a1\u5668\u5c42\u7684\u65e5\u5fd7&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u6307\u5b9a\u9608\u503c\u7684 SQL \u8bed\u53e5&#xff0c;\u662f\u6392\u67e5 MySQL \u6027\u80fd\u95ee\u9898\u3001\u4f18\u5316 SQL \u7684\u6838\u5fc3\u5de5\u5177&#xff0c;\u4e5f\u662f\u540e\u7aef\u5f00\u53d1\u548c DBA \u65e5\u5e38\u5de5\u4f5c\u4e2d\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u65e5\u5fd7\u3002<\/p>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>\u901a\u8fc7\u8bbe\u7f6e\u6162\u67e5\u8be2\u9608\u503c&#xff08;\u5982 1 \u79d2&#xff09;&#xff0c;MySQL \u4f1a\u81ea\u52a8\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u8be5\u9608\u503c\u3001\u4e14\u626b\u63cf\u884c\u6570\u8fbe\u5230\u6307\u5b9a\u6761\u4ef6\u7684 SQL \u8bed\u53e5&#xff0c;\u540c\u65f6\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\u3001\u626b\u63cf\u884c\u6570\u3001\u6267\u884c\u7528\u6237\u3001\u6267\u884c\u65f6\u95f4\u7b49\u5173\u952e\u4fe1\u606f&#xff0c;\u4ee5\u6587\u672c\u683c\u5f0f\u5b58\u50a8&#xff0c;\u53ef\u76f4\u63a5\u67e5\u770b\u3002<\/p>\n<h5>\u6838\u5fc3\u4f5c\u7528<\/h5>\n<ul>\n<li>\u5b9a\u4f4d\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u6162 SQL&#xff0c;\u662f SQL \u4f18\u5316\u7684\u552f\u4e00\u5165\u53e3&#xff1b;<\/li>\n<li>\u5206\u6790\u6570\u636e\u5e93\u7684\u6027\u80fd\u74f6\u9888&#xff08;\u5982\u5927\u91cf\u5168\u8868\u626b\u63cf\u3001\u8054\u8868\u67e5\u8be2\u65e0\u7d22\u5f15\u3001\u5927\u4e8b\u52a1\u7b49&#xff09;&#xff1b;<\/li>\n<li>\u4f18\u5316\u6570\u636e\u5e93\u7d22\u5f15\u3001SQL \u8bed\u53e5\u3001\u8868\u7ed3\u6784\u7684\u4f9d\u636e\u3002<\/li>\n<\/ul>\n<h5>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h5>\n<ul>\n<li>\u751f\u4ea7\u73af\u5883\u6570\u636e\u5e93 CPU\/IO \u5229\u7528\u7387\u8fc7\u9ad8\u65f6&#xff0c;\u6392\u67e5\u6162 SQL&#xff1b;<\/li>\n<li>\u9879\u76ee\u4e0a\u7ebf\u524d\u7684SQL \u6027\u80fd\u68c0\u6d4b&#xff0c;\u907f\u514d\u6162 SQL \u4e0a\u7ebf&#xff1b;<\/li>\n<li>\u5b9a\u671f\u5206\u6790\u6162\u67e5\u8be2\u65e5\u5fd7&#xff0c;\u4f18\u5316\u6570\u636e\u5e93\u6027\u80fd&#xff0c;\u9884\u9632\u6027\u80fd\u95ee\u9898\u3002<\/li>\n<\/ul>\n<h5>\u5173\u952e\u914d\u7f6e&#xff08;\u9ed8\u8ba4\u5173\u95ed&#xff0c;\u9700\u624b\u52a8\u5f00\u542f&#xff09;<\/h5>\n<p># \u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7<br \/>\nslow_query_log &#061; ON<br \/>\n# \u6162\u67e5\u8be2\u65e5\u5fd7\u7684\u5b58\u50a8\u8def\u5f84<br \/>\nslow_query_log_file &#061; \/var\/lib\/mysql\/mysql-slow.log<br \/>\n# \u6162\u67e5\u8be2\u9608\u503c&#xff0c;\u5355\u4f4d\u79d2&#xff0c;\u751f\u4ea7\u5efa\u8bae0.5-1\u79d2&#xff08;\u6839\u636e\u4e1a\u52a1\u8c03\u6574&#xff09;<br \/>\nlong_query_time &#061; 1<br \/>\n# \u8bb0\u5f55\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u9608\u503c\u4f46\u672a\u4f7f\u7528\u7d22\u5f15\u7684SQL&#xff08;\u751f\u4ea7\u5efa\u8bae\u5f00\u542f&#xff09;<br \/>\nlog_queries_not_using_indexes &#061; ON<br \/>\n# \u5ffd\u7565\u626b\u63cf\u884c\u6570\u8fc7\u5c11\u7684\u6162SQL&#xff0c;\u907f\u514d\u65e5\u5fd7\u5197\u4f59&#xff0c;\u9ed8\u8ba41000<br \/>\nmin_examined_row_limit &#061; 1000<br \/>\n# \u8bb0\u5f55\u6162\u67e5\u8be2\u7684\u65b9\u5f0f&#xff0c;\u9ed8\u8ba4FILE&#xff08;\u6587\u4ef6&#xff09;&#xff0c;\u4e5f\u53ef\u8bbe\u7f6e\u4e3aTABLE&#xff08;\u5b58\u50a8\u5230mysql.slow_log\u8868&#xff09;<br \/>\nlog_output &#061; FILE<\/p>\n<h5>\u6838\u5fc3\u5206\u6790\u5de5\u5177<\/h5>\n<ul>\n<li>\n<p>mysqldumpslow&#xff1a;MySQL \u81ea\u5e26\u7684\u6162\u67e5\u8be2\u5206\u6790\u5de5\u5177&#xff0c;\u53ef\u6309\u6267\u884c\u6b21\u6570\u3001\u6267\u884c\u65f6\u95f4\u3001\u9501\u65f6\u95f4\u7b49\u7ef4\u5ea6\u7edf\u8ba1\u6162 SQL&#xff1b;<\/p>\n<p> <span class=\"token comment\"># \u67e5\u770b\u6267\u884c\u6b21\u6570\u6700\u591a\u768410\u6761\u6162SQL<\/span><br \/>\nmysqldumpslow -s c -n <span class=\"token number\">10<\/span> \/var\/lib\/mysql\/mysql-slow.log<br \/>\n<span class=\"token comment\"># \u67e5\u770b\u6267\u884c\u65f6\u95f4\u6700\u957f\u768410\u6761\u6162SQL<\/span><br \/>\nmysqldumpslow -s t -n <span class=\"token number\">10<\/span> \/var\/lib\/mysql\/mysql-slow.log\n <\/li>\n<li>\n<p>pt-query-digest&#xff1a;Percona \u5de5\u5177\u96c6\u7684\u6162\u67e5\u8be2\u5206\u6790\u5de5\u5177&#xff0c;\u529f\u80fd\u6bd4 mysqldumpslow \u66f4\u5f3a\u5927&#xff0c;\u53ef\u751f\u6210\u8be6\u7ec6\u7684\u5206\u6790\u62a5\u544a&#xff0c;\u662f\u751f\u4ea7\u73af\u5883\u9996\u9009\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>&#xff08;\u56db&#xff09;\u9519\u8bef\u65e5\u5fd7&#xff1a;error log&#xff08;\u6545\u969c\u6392\u67e5\u6838\u5fc3&#xff09;<\/h4>\n<p>\u9519\u8bef\u65e5\u5fd7\u662f MySQL\u6700\u91cd\u8981\u7684\u65e5\u5fd7&#xff0c;\u4e5f\u662f\u9ed8\u8ba4\u5f00\u542f\u7684\u65e5\u5fd7&#xff0c;\u8bb0\u5f55\u4e86 MySQL \u4ece\u542f\u52a8\u5230\u5173\u95ed\u7684\u6240\u6709\u5173\u952e\u4e8b\u4ef6&#xff0c;\u5305\u62ec\u542f\u52a8 \/ \u5173\u95ed\u4fe1\u606f\u3001\u914d\u7f6e\u52a0\u8f7d\u4fe1\u606f\u3001\u5f02\u5e38\u9519\u8bef\u4fe1\u606f\u3001\u8b66\u544a\u4fe1\u606f\u3001\u540e\u53f0\u7ebf\u7a0b\u8fd0\u884c\u4fe1\u606f\u7b49\u3002<\/p>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>MySQL \u542f\u52a8\u65f6\u81ea\u52a8\u5f00\u542f\u9519\u8bef\u65e5\u5fd7&#xff0c;\u4ee5\u6587\u672c\u683c\u5f0f\u5b58\u50a8&#xff0c;\u8bb0\u5f55\u6240\u6709\u7ea7\u522b\u7684\u9519\u8bef\u548c\u8b66\u544a\u4fe1\u606f&#xff0c;\u662f\u6392\u67e5 MySQL \u542f\u52a8\u5931\u8d25\u3001\u8fd0\u884c\u5f02\u5e38\u7684\u7b2c\u4e00\u624b\u8d44\u6599\u3002<\/p>\n<h5>\u6838\u5fc3\u4f5c\u7528<\/h5>\n<ul>\n<li>\u6392\u67e5 MySQL\u542f\u52a8\u5931\u8d25\u95ee\u9898&#xff08;\u5982\u914d\u7f6e\u6587\u4ef6\u9519\u8bef\u3001\u7aef\u53e3\u88ab\u5360\u7528\u3001\u6570\u636e\u6587\u4ef6\u635f\u574f\u7b49&#xff09;&#xff1b;<\/li>\n<li>\u6392\u67e5 MySQL \u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u5f02\u5e38\u95ee\u9898&#xff08;\u5982\u8fde\u63a5\u6570\u6ee1\u3001\u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\u3001\u4e3b\u4ece\u540c\u6b65\u5931\u8d25\u7b49&#xff09;&#xff1b;<\/li>\n<li>\u76d1\u63a7 MySQL \u7684\u8fd0\u884c\u72b6\u6001&#xff0c;\u53ca\u65f6\u53d1\u73b0\u6f5c\u5728\u7684\u8b66\u544a\u4fe1\u606f&#xff08;\u5982\u7d22\u5f15\u5931\u6548\u3001\u78c1\u76d8 IO \u8fc7\u9ad8&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h5>\n<ul>\n<li>MySQL \u670d\u52a1\u65e0\u6cd5\u542f\u52a8\u65f6&#xff0c;\u4f18\u5148\u67e5\u770b\u9519\u8bef\u65e5\u5fd7&#xff1b;<\/li>\n<li>\u751f\u4ea7\u73af\u5883 MySQL \u51fa\u73b0\u8fde\u63a5\u5f02\u5e38\u3001\u4e3b\u4ece\u540c\u6b65\u4e2d\u65ad\u65f6&#xff0c;\u6392\u67e5\u9519\u8bef\u65e5\u5fd7&#xff1b;<\/li>\n<li>\u5b9a\u671f\u68c0\u67e5\u9519\u8bef\u65e5\u5fd7&#xff0c;\u6e05\u7406\u8b66\u544a\u4fe1\u606f&#xff0c;\u9884\u9632\u6545\u969c\u53d1\u751f\u3002<\/li>\n<\/ul>\n<h5>\u5173\u952e\u914d\u7f6e&#xff08;\u9ed8\u8ba4\u5f00\u542f&#xff0c;\u4ec5\u9700\u914d\u7f6e\u5b58\u50a8\u8def\u5f84&#xff09;<\/h5>\n<p># \u9519\u8bef\u65e5\u5fd7\u7684\u5b58\u50a8\u8def\u5f84&#xff0c;\u9ed8\u8ba4\/var\/lib\/mysql\/\u4e3b\u673a\u540d.err<br \/>\nlog_error &#061; \/var\/lib\/mysql\/mysql-error.log<br \/>\n# \u65e5\u5fd7\u7ea7\u522b&#xff0c;\u9ed8\u8ba4ERROR&#xff0c;\u53ef\u8bbe\u7f6e\u4e3aWARNING\/INFO\/DEBUG&#xff0c;\u751f\u4ea7\u5efa\u8baeERROR<br \/>\nlog_error_verbosity &#061; 2<\/p>\n<h4>&#xff08;\u4e94&#xff09;\u4e2d\u7ee7\u65e5\u5fd7&#xff1a;relay log&#xff08;\u4ece\u5e93\u4e13\u5c5e&#xff0c;\u4e3b\u4ece\u540c\u6b65\u6838\u5fc3&#xff09;<\/h4>\n<p>\u4e2d\u7ee7\u65e5\u5fd7\u662f MySQL\u4ece\u5e93\u4e13\u5c5e\u7684\u65e5\u5fd7&#xff0c;\u4e3b\u5e93\u65e0\u6b64\u65e5\u5fd7&#xff0c;\u662f\u4e3b\u4ece\u590d\u5236\u8fc7\u7a0b\u4e2d\u7684\u4e2d\u95f4\u65e5\u5fd7\u3002<\/p>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>\u4e3b\u4ece\u590d\u5236\u8fc7\u7a0b\u4e2d&#xff0c;\u4ece\u5e93\u7684 IO \u7ebf\u7a0b\u4ece\u4e3b\u5e93\u8bfb\u53d6 binlog \u65e5\u5fd7&#xff0c;\u5199\u5165\u5230\u672c\u5730\u7684\u4e2d\u7ee7\u65e5\u5fd7\u4e2d&#xff0c;\u7136\u540e\u4ece\u5e93\u7684 SQL \u7ebf\u7a0b\u89e3\u6790\u4e2d\u7ee7\u65e5\u5fd7&#xff0c;\u6267\u884c\u76f8\u540c\u7684\u4fee\u6539\u64cd\u4f5c&#xff0c;\u5b9e\u73b0\u4e3b\u4ece\u6570\u636e\u540c\u6b65\u3002\u4e2d\u7ee7\u65e5\u5fd7\u7684\u683c\u5f0f\u4e0e binlog \u5b8c\u5168\u4e00\u81f4&#xff0c;\u4ec5\u4f5c\u7528\u4e8e\u4ece\u5e93\u3002<\/p>\n<h5>\u6838\u5fc3\u4f5c\u7528<\/h5>\n<ul>\n<li>\u4e3b\u4ece\u590d\u5236\u7684\u4e2d\u95f4\u6865\u6881&#xff0c;\u89e3\u8026\u4e3b\u5e93 binlog \u8bfb\u53d6\u548c\u4ece\u5e93 SQL \u6267\u884c&#xff0c;\u63d0\u5347\u4e3b\u4ece\u540c\u6b65\u6027\u80fd&#xff1b;<\/li>\n<li>\u82e5\u4ece\u5e93 SQL \u7ebf\u7a0b\u6267\u884c\u7f13\u6162&#xff0c;\u4e2d\u7ee7\u65e5\u5fd7\u4f1a\u6682\u5b58\u672a\u6267\u884c\u7684 binlog \u5185\u5bb9&#xff0c;\u907f\u514d\u4e3b\u5e93 binlog \u88ab\u6e05\u7406\u5bfc\u81f4\u540c\u6b65\u5931\u8d25\u3002<\/li>\n<\/ul>\n<h5>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h5>\n<ul>\n<li>\u4e3b\u4ece\u540c\u6b65\u4e2d\u65ad\u65f6&#xff0c;\u6392\u67e5\u4e2d\u7ee7\u65e5\u5fd7\u662f\u5426\u635f\u574f\u3001\u662f\u5426\u6709\u672a\u6267\u884c\u7684\u5185\u5bb9&#xff1b;<\/li>\n<li>\u4ece\u5e93\u6027\u80fd\u8c03\u4f18\u65f6&#xff0c;\u76d1\u63a7\u4e2d\u7ee7\u65e5\u5fd7\u7684\u5199\u5165\u548c\u6267\u884c\u901f\u5ea6&#xff0c;\u5b9a\u4f4d\u540c\u6b65\u5ef6\u8fdf\u95ee\u9898\u3002<\/li>\n<\/ul>\n<h5>\u5173\u952e\u914d\u7f6e&#xff08;\u4ece\u5e93\u4e13\u5c5e&#xff0c;\u9ed8\u8ba4\u5f00\u542f&#xff09;<\/h5>\n<p># \u4e2d\u7ee7\u65e5\u5fd7\u7684\u5b58\u50a8\u8def\u5f84\u548c\u524d\u7f00<br \/>\nrelay_log &#061; \/var\/lib\/mysql\/relay-bin<br \/>\n# \u4e2d\u7ee7\u65e5\u5fd7\u7d22\u5f15\u6587\u4ef6<br \/>\nrelay_log_index &#061; \/var\/lib\/mysql\/relay-bin.index<br \/>\n# \u4e2d\u7ee7\u65e5\u5fd7\u8fc7\u671f\u6e05\u7406\u65f6\u95f4&#xff0c;\u9ed8\u8ba4\u4e0ebinlog\u4e00\u81f4<br \/>\nrelay_log_expire_logs_days &#061; 7<br \/>\n# \u4ece\u5e93SQL\u7ebf\u7a0b\u6267\u884c\u5b8c\u4e2d\u7ee7\u65e5\u5fd7\u540e&#xff0c;\u662f\u5426\u81ea\u52a8\u6e05\u7406&#xff0c;\u9ed8\u8ba4\u5f00\u542f<br \/>\nrelay_log_purge &#061; ON<\/p>\n<h4>&#xff08;\u516d&#xff09;\u901a\u7528\u67e5\u8be2\u65e5\u5fd7&#xff1a;general query log&#xff08;\u5168\u91cf SQL \u8bb0\u5f55&#xff09;<\/h4>\n<p>\u901a\u7528\u67e5\u8be2\u65e5\u5fd7\u662f MySQL \u670d\u52a1\u5668\u5c42\u7684\u65e5\u5fd7&#xff0c;\u8bb0\u5f55\u4e86\u6240\u6709\u5bf9 MySQL \u7684\u8fde\u63a5\u8bf7\u6c42\u548c\u6267\u884c\u7684 SQL \u8bed\u53e5&#xff08;\u5305\u62ec\u67e5\u3001\u589e\u3001\u5220\u3001\u6539&#xff09;&#xff0c;\u9ed8\u8ba4\u5173\u95ed\u3002<\/p>\n<h5>\u6838\u5fc3\u539f\u7406<\/h5>\n<p>\u5f00\u542f\u540e&#xff0c;MySQL \u4f1a\u8bb0\u5f55\u6240\u6709\u7528\u6237\u7684\u8fde\u63a5\u4fe1\u606f&#xff08;\u8fde\u63a5\u65f6\u95f4\u3001\u65ad\u5f00\u65f6\u95f4\u3001\u7528\u6237 IP&#xff09;\u548c\u6267\u884c\u7684\u6240\u6709 SQL \u8bed\u53e5&#xff0c;\u4ee5\u6587\u672c\u683c\u5f0f\u5b58\u50a8&#xff0c;\u65e5\u5fd7\u4f53\u79ef\u4f1a\u5feb\u901f\u81a8\u80c0\u3002<\/p>\n<h5>\u6838\u5fc3\u4f5c\u7528<\/h5>\n<ul>\n<li>\u5168\u91cf SQL \u5ba1\u8ba1&#xff0c;\u8ffd\u6eaf\u6240\u6709\u7528\u6237\u7684\u64cd\u4f5c\u884c\u4e3a&#xff1b;<\/li>\n<li>\u6392\u67e5\u5f00\u53d1\u73af\u5883\u4e2d\u7684SQL \u6267\u884c\u95ee\u9898&#xff08;\u5982\u67d0\u4e2a SQL \u662f\u5426\u6267\u884c\u3001\u6267\u884c\u7684\u987a\u5e8f\u662f\u4ec0\u4e48&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h5>\n<ul>\n<li>\u5f00\u53d1\u73af\u5883\u4e2d\u6392\u67e5 SQL \u6267\u884c\u5f02\u5e38\u95ee\u9898&#xff0c;\u4e34\u65f6\u5f00\u542f\u901a\u7528\u67e5\u8be2\u65e5\u5fd7&#xff1b;<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u4e2d\u4e34\u65f6\u5b9a\u4f4d\u6570\u636e\u53d8\u66f4\u7684\u6e90\u5934&#xff08;\u4e0d\u5efa\u8bae\u957f\u671f\u5f00\u542f&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u5173\u952e\u914d\u7f6e&#xff08;\u9ed8\u8ba4\u5173\u95ed&#xff0c;\u7981\u6b62\u957f\u671f\u5f00\u542f&#xff09;<\/h5>\n<p># \u5f00\u542f\u901a\u7528\u67e5\u8be2\u65e5\u5fd7&#xff0c;\u751f\u4ea7\u73af\u5883\u7981\u6b62\u957f\u671f\u5f00\u542f<br \/>\ngeneral_log &#061; ON<br \/>\n# \u901a\u7528\u67e5\u8be2\u65e5\u5fd7\u7684\u5b58\u50a8\u8def\u5f84<br \/>\ngeneral_log_file &#061; \/var\/lib\/mysql\/mysql-general.log<br \/>\n# \u65e5\u5fd7\u5b58\u50a8\u65b9\u5f0f&#xff0c;\u9ed8\u8ba4FILE&#xff0c;\u4e5f\u53ef\u8bbe\u7f6e\u4e3aTABLE<br \/>\nlog_output &#061; FILE<\/p>\n<p>\u6ce8\u610f&#xff1a;\u901a\u7528\u67e5\u8be2\u65e5\u5fd7\u4f1a\u8bb0\u5f55\u6240\u6709 SQL&#xff0c;\u5305\u62ec\u9ad8\u9891\u67e5\u8be2&#xff0c;\u65e5\u5fd7\u4f53\u79ef\u4f1a\u5448\u6307\u6570\u7ea7\u589e\u957f&#xff0c;\u751f\u4ea7\u73af\u5883\u4e25\u7981\u957f\u671f\u5f00\u542f&#xff0c;\u4ec5\u53ef\u4e34\u65f6\u5f00\u542f\u6392\u67e5\u95ee\u9898&#xff0c;\u6392\u67e5\u5b8c\u6210\u540e\u7acb\u5373\u5173\u95ed\u3002<\/p>\n<h3>\u4e09\u3001MySQL \u65e5\u5fd7\u7684\u751f\u4ea7\u73af\u5883\u6838\u5fc3\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h3>\n<p>\u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;MySQL \u65e5\u5fd7\u7684\u914d\u7f6e\u3001\u7ba1\u7406\u3001\u7ef4\u62a4\u662f\u4fdd\u969c\u6570\u636e\u5e93\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e&#xff0c;\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u65e5\u5fd7\u6587\u4ef6\u8fc7\u5927\u5360\u6ee1\u78c1\u76d8\u3001\u4e3b\u4ece\u540c\u6b65\u56e0\u65e5\u5fd7\u95ee\u9898\u4e2d\u65ad\u3001\u6162\u67e5\u8be2\u65e5\u5fd7\u65e0\u6709\u6548\u4fe1\u606f\u3001\u6570\u636e\u6062\u590d\u5931\u8d25\u7b49&#xff0c;\u4ee5\u4e0b\u9488\u5bf9\u9ad8\u9891\u95ee\u9898\u7ed9\u51fa\u5b9e\u6218\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<h4>\u95ee\u9898 1&#xff1a;binlog \/ \u6162\u67e5\u8be2\u65e5\u5fd7\u8fc7\u5927&#xff0c;\u5360\u6ee1\u78c1\u76d8\u7a7a\u95f4<\/h4>\n<p>\u95ee\u9898\u539f\u56e0&#xff1a;\u672a\u914d\u7f6e\u65e5\u5fd7\u8fc7\u671f\u6e05\u7406\u65f6\u95f4&#xff0c;\u6216\u65e5\u5fd7\u6587\u4ef6\u5927\u5c0f\u8bbe\u7f6e\u8fc7\u5927&#xff0c;\u5bfc\u81f4\u65e5\u5fd7\u6587\u4ef6\u6301\u7eed\u7d2f\u79ef&#xff0c;\u5360\u6ee1\u78c1\u76d8\u3002\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\n<p>\u914d\u7f6e\u65e5\u5fd7\u8fc7\u671f\u6e05\u7406\u65f6\u95f4&#xff0c;binlog \u548c\u4e2d\u7ee7\u65e5\u5fd7\u5efa\u8bae\u8bbe\u7f6e 7-15 \u5929&#xff0c;\u6162\u67e5\u8be2\u65e5\u5fd7\u5efa\u8bae\u8bbe\u7f6e 3-7 \u5929&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u9650\u5236\u5355\u4e2a\u65e5\u5fd7\u6587\u4ef6\u7684\u5927\u5c0f&#xff0c;binlog \u5efa\u8bae 1-2G&#xff0c;\u907f\u514d\u5355\u4e2a\u6587\u4ef6\u8fc7\u5927\u5bfc\u81f4\u89e3\u6790\u56f0\u96be&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5f00\u542f\u81ea\u52a8\u6e05\u7406&#xff0c;\u786e\u4fdd MySQL \u540e\u53f0\u7ebf\u7a0b\u53ca\u65f6\u6e05\u7406\u8fc7\u671f\u65e5\u5fd7&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u624b\u52a8\u6e05\u7406\u8fc7\u671f\u65e5\u5fd7&#xff08;\u907f\u514d\u76f4\u63a5\u5220\u9664\u6587\u4ef6&#xff0c;\u4f7f\u7528 MySQL \u5b98\u65b9\u547d\u4ee4&#xff09;&#xff1a;<\/p>\n<p> <span class=\"token comment\">&#8212; \u6e05\u7406binlog&#xff0c;\u4fdd\u7559\u6307\u5b9a\u65f6\u95f4\u540e\u7684\u65e5\u5fd7<\/span><br \/>\n<span class=\"token keyword\">PURGE<\/span> <span class=\"token keyword\">BINARY<\/span> LOGS BEFORE <span class=\"token string\">&#039;2026-01-01 00:00:00&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">&#8212; \u6e05\u7406binlog&#xff0c;\u4fdd\u7559\u6307\u5b9a\u6587\u4ef6\u540e\u7684\u65e5\u5fd7<\/span><br \/>\n<span class=\"token keyword\">PURGE<\/span> <span class=\"token keyword\">BINARY<\/span> LOGS <span class=\"token keyword\">TO<\/span> <span class=\"token string\">&#039;mysql-bin.000005&#039;<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u914d\u7f6e\u78c1\u76d8\u76d1\u63a7\u544a\u8b66&#xff0c;\u5f53\u78c1\u76d8\u4f7f\u7528\u7387\u8d85\u8fc7 80% \u65f6\u53ca\u65f6\u544a\u8b66&#xff0c;\u907f\u514d\u78c1\u76d8\u5360\u6ee1\u3002<\/p>\n<\/li>\n<h4>\u95ee\u9898 2&#xff1a;\u4e3b\u4ece\u540c\u6b65\u56e0 binlog \/ \u4e2d\u7ee7\u65e5\u5fd7\u635f\u574f\u4e2d\u65ad<\/h4>\n<p>\u95ee\u9898\u539f\u56e0&#xff1a;\u78c1\u76d8 IO \u5f02\u5e38\u3001\u670d\u52a1\u5668\u5b95\u673a\u3001\u4eba\u4e3a\u8bef\u5220\u65e5\u5fd7\u6587\u4ef6&#xff0c;\u5bfc\u81f4 binlog \u6216\u4e2d\u7ee7\u65e5\u5fd7\u635f\u574f&#xff0c;\u4e3b\u4ece\u540c\u6b65\u4e2d\u65ad\u3002\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<h5>\u573a\u666f 2.1&#xff1a;\u4e2d\u7ee7\u65e5\u5fd7\u635f\u574f&#xff08;\u4ece\u5e93&#xff09;<\/h5>\n<li>\n<p>\u505c\u6b62\u4ece\u5e93\u7684\u4e3b\u4ece\u540c\u6b65&#xff1a;STOP SLAVE;<\/p>\n<\/li>\n<li>\n<p>\u91cd\u7f6e\u4e2d\u7ee7\u65e5\u5fd7&#xff1a;RESET SLAVE;<\/p>\n<\/li>\n<li>\n<p>\u91cd\u65b0\u6307\u5b9a\u4e3b\u5e93\u4fe1\u606f&#xff0c;\u5f00\u542f\u540c\u6b65&#xff1a;<\/p>\n<p> CHANGE MASTER <span class=\"token keyword\">TO<\/span><br \/>\nMASTER_HOST<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u4e3b\u5e93IP&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\nMASTER_USER<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u590d\u5236\u8d26\u53f7&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\nMASTER_PASSWORD<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u590d\u5236\u5bc6\u7801&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\nMASTER_LOG_FILE<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u4e3b\u5e93\u5f53\u524dbinlog\u6587\u4ef6&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\nMASTER_LOG_POS<span class=\"token operator\">&#061;<\/span>\u4e3b\u5e93\u5f53\u524dbinlog\u4f4d\u7f6e<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">START<\/span> SLAVE<span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u68c0\u67e5\u540c\u6b65\u72b6\u6001&#xff1a;SHOW SLAVE STATUS\\\\G;&#xff08;\u786e\u4fdd Slave_IO_Running \u548c Slave_SQL_Running \u5747\u4e3a Yes&#xff09;\u3002<\/p>\n<\/li>\n<h5>\u573a\u666f 2.2&#xff1a;\u4e3b\u5e93 binlog \u635f\u574f&#xff08;\u4e3b\u5e93&#xff09;<\/h5>\n<li>\u82e5\u4e3b\u5e93\u6709\u5907\u5e93&#xff0c;\u76f4\u63a5\u5c06\u5907\u5e93\u63d0\u5347\u4e3a\u4e3b\u5e93&#xff0c;\u91cd\u65b0\u642d\u5efa\u4e3b\u4ece&#xff1b;<\/li>\n<li>\u82e5\u65e0\u5907\u5e93&#xff0c;\u9700\u91cd\u65b0\u5168\u91cf\u5907\u4efd\u4e3b\u5e93\u6570\u636e&#xff0c;\u5bfc\u5165\u4ece\u5e93&#xff0c;\u518d\u91cd\u65b0\u642d\u5efa\u4e3b\u4ece&#xff1b;\u9884\u9632\u65b9\u6848&#xff1a;\u4e3b\u5e93\u5f00\u542f binlog \u7684\u6821\u9a8c\u548c&#xff0c;\u68c0\u6d4b\u65e5\u5fd7\u635f\u574f&#xff1a;binlog_checksum &#061; CRC32\u3002<\/li>\n<h4>\u95ee\u9898 3&#xff1a;\u6162\u67e5\u8be2\u65e5\u5fd7\u65e0\u6709\u6548\u4fe1\u606f&#xff0c;\u65e0\u6cd5\u5b9a\u4f4d\u6162 SQL<\/h4>\n<p>\u95ee\u9898\u539f\u56e0&#xff1a;\u6162\u67e5\u8be2\u9608\u503c\u8bbe\u7f6e\u8fc7\u5927\u3001\u672a\u5f00\u542f \u201c\u8bb0\u5f55\u65e0\u7d22\u5f15 SQL\u201d\u3001\u5ffd\u7565\u4e86\u626b\u63cf\u884c\u6570\u8fc7\u5c11\u7684 SQL&#xff0c;\u6216\u65e5\u5fd7\u8f93\u51fa\u65b9\u5f0f\u914d\u7f6e\u9519\u8bef\u3002\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\u964d\u4f4e\u6162\u67e5\u8be2\u9608\u503c&#xff0c;\u6839\u636e\u4e1a\u52a1\u573a\u666f\u8c03\u6574\u4e3a 0.5-1 \u79d2&#xff0c;\u6355\u6349\u66f4\u591a\u6162 SQL&#xff1b;<\/li>\n<li>\u5f00\u542flog_queries_not_using_indexes &#061; ON&#xff0c;\u8bb0\u5f55\u6240\u6709\u672a\u4f7f\u7528\u7d22\u5f15\u7684 SQL&#xff0c;\u5373\u4f7f\u6267\u884c\u65f6\u95f4\u672a\u8d85\u8fc7\u9608\u503c&#xff1b;<\/li>\n<li>\u964d\u4f4emin_examined_row_limit&#xff0c;\u907f\u514d\u5ffd\u7565\u626b\u63cf\u884c\u6570\u8f83\u5c11\u4f46\u6267\u884c\u9891\u7e41\u7684\u6162 SQL&#xff1b;<\/li>\n<li>\u786e\u8ba4\u65e5\u5fd7\u8f93\u51fa\u65b9\u5f0f\u4e3aFILE&#xff0c;\u5e76\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u7684\u6743\u9650&#xff08;\u786e\u4fdd MySQL \u6709\u5199\u5165\u6743\u9650&#xff09;&#xff1b;<\/li>\n<li>\u4f7f\u7528pt-query-digest\u5de5\u5177\u5206\u6790\u6162\u67e5\u8be2\u65e5\u5fd7&#xff0c;\u907f\u514d\u624b\u52a8\u67e5\u770b\u9057\u6f0f\u5173\u952e\u4fe1\u606f\u3002<\/li>\n<h4>\u95ee\u9898 4&#xff1a;\u6570\u636e\u5e93\u5d29\u6e83\u540e&#xff0c;\u901a\u8fc7 redo log \u6062\u590d\u6570\u636e\u5931\u8d25<\/h4>\n<p>\u95ee\u9898\u539f\u56e0&#xff1a;redo log \u5237\u76d8\u7b56\u7565\u914d\u7f6e\u4e0d\u5f53&#xff08;\u5982innodb_flush_log_at_trx_commit &#061; 0&#xff09;&#xff0c;\u6216 redo log \u6587\u4ef6\u635f\u574f\u3002\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\u751f\u4ea7\u73af\u5883\u5f3a\u5236\u914d\u7f6einnodb_flush_log_at_trx_commit &#061; 1\u548csync_binlog &#061; 1&#xff08;\u53cc 1 \u914d\u7f6e&#xff09;&#xff0c;\u786e\u4fdd\u4e8b\u52a1\u63d0\u4ea4\u65f6\u65e5\u5fd7\u5237\u76d8&#xff0c;\u4fdd\u969c\u6301\u4e45\u6027&#xff1b;<\/li>\n<li>\u82e5 redo log \u6587\u4ef6\u635f\u574f&#xff0c;\u5c1d\u8bd5\u901a\u8fc7 MySQL \u5b98\u65b9\u5de5\u5177innochecksum\u68c0\u6d4b\u5e76\u4fee\u590d\u6570\u636e\u6587\u4ef6&#xff1b;<\/li>\n<li>\u82e5\u4fee\u590d\u5931\u8d25&#xff0c;\u4f7f\u7528\u5168\u91cf\u5907\u4efd &#043; binlog \u6062\u590d\u6570\u636e&#xff08;\u8fd9\u662f\u751f\u4ea7\u73af\u5883\u6700\u53ef\u9760\u7684\u6062\u590d\u65b9\u5f0f&#xff09;\u3002<\/li>\n<h4>\u95ee\u9898 5&#xff1a;\u6570\u636e\u8bef\u5220\u540e&#xff0c;\u901a\u8fc7 binlog \u6062\u590d\u6570\u636e\u5931\u8d25<\/h4>\n<p>\u95ee\u9898\u539f\u56e0&#xff1a;binlog \u65e5\u5fd7\u5df2\u88ab\u6e05\u7406\u3001binlog \u683c\u5f0f\u4e3a Statement \u5bfc\u81f4 SQL \u91cd\u653e\u5931\u8d25\u3001\u672a\u8bb0\u5f55\u5230\u8bef\u5220\u64cd\u4f5c\u7684 binlog \u6587\u4ef6\u3002\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\u914d\u7f6e\u5408\u7406\u7684expire_logs_days&#xff0c;\u786e\u4fdd binlog \u65e5\u5fd7\u4fdd\u7559\u8db3\u591f\u957f\u7684\u65f6\u95f4&#xff08;\u81f3\u5c11 7 \u5929&#xff09;&#xff0c;\u5e76\u5b9a\u671f\u5907\u4efd binlog \u65e5\u5fd7&#xff1b;<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u5f3a\u5236\u4f7f\u7528binlog_format &#061; ROW&#xff0c;\u907f\u514d Statement \u683c\u5f0f\u7684\u4e3b\u4ece\u4e0d\u4e00\u81f4\u548c\u6062\u590d\u5931\u8d25\u95ee\u9898&#xff1b;<\/li>\n<li>\u82e5\u8bef\u5220\u64cd\u4f5c\u7684 binlog \u5df2\u88ab\u6e05\u7406&#xff0c;\u4f7f\u7528\u6700\u8fd1\u7684\u5168\u91cf\u5907\u4efd&#043;\u589e\u91cf\u5907\u4efd\u6062\u590d\u6570\u636e&#xff1b;\u9884\u9632\u65b9\u6848&#xff1a;\u751f\u4ea7\u73af\u5883\u5f00\u542f\u6570\u636e\u5907\u4efd\u7b56\u7565&#xff08;\u5168\u91cf &#043; \u589e\u91cf&#xff09;&#xff0c;\u5e76\u5b9a\u671f\u6d4b\u8bd5\u6062\u590d\u6d41\u7a0b&#xff0c;\u786e\u4fdd\u5907\u4efd\u53ef\u7528\u3002<\/li>\n<h3>\u56db\u3001MySQL \u65e5\u5fd7\u7684\u751f\u4ea7\u73af\u5883\u6700\u4f73\u5b9e\u8df5<\/h3>\n<h4>1. \u65e5\u5fd7\u914d\u7f6e\u6700\u4f73\u5b9e\u8df5<\/h4>\n<ul>\n<li>\u53cc 1 \u914d\u7f6e&#xff1a;\u751f\u4ea7\u73af\u5883\u5fc5\u987b\u8bbe\u7f6einnodb_flush_log_at_trx_commit &#061; 1\u548csync_binlog &#061; 1&#xff0c;\u4fdd\u969c\u6570\u636e\u6301\u4e45\u6027&#xff1b;<\/li>\n<li>binlog \u6838\u5fc3\u914d\u7f6e&#xff1a;\u5f00\u542f binlog&#xff0c;\u683c\u5f0f\u4e3a ROW&#xff0c;\u8fc7\u671f\u65f6\u95f4 7-15 \u5929&#xff0c;\u5355\u4e2a\u6587\u4ef6 1-2G&#xff1b;<\/li>\n<li>\u6162\u67e5\u8be2\u914d\u7f6e&#xff1a;\u5f00\u542f\u6162\u67e5\u8be2&#xff0c;\u9608\u503c 0.5-1 \u79d2&#xff0c;\u8bb0\u5f55\u65e0\u7d22\u5f15 SQL&#xff0c;\u4f7f\u7528 pt-query-digest \u5206\u6790&#xff1b;<\/li>\n<li>\u65e5\u5fd7\u8def\u5f84\u5206\u79bb&#xff1a;\u5c06\u65e5\u5fd7\u6587\u4ef6\u4e0e\u6570\u636e\u6587\u4ef6\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u78c1\u76d8&#xff0c;\u907f\u514d\u65e5\u5fd7\u5199\u6ee1\u5bfc\u81f4\u6570\u636e\u6587\u4ef6\u65e0\u6cd5\u5199\u5165&#xff1b;<\/li>\n<li>\u7981\u6b62\u957f\u671f\u5f00\u542f\u901a\u7528\u67e5\u8be2\u65e5\u5fd7&#xff1a;\u4ec5\u53ef\u4e34\u65f6\u5f00\u542f\u6392\u67e5\u95ee\u9898&#xff0c;\u6392\u67e5\u5b8c\u6210\u540e\u7acb\u5373\u5173\u95ed\u3002<\/li>\n<\/ul>\n<h4>2. \u65e5\u5fd7\u7ba1\u7406\u6700\u4f73\u5b9e\u8df5<\/h4>\n<ul>\n<li>\u5b9a\u671f\u6e05\u7406\u8fc7\u671f\u65e5\u5fd7&#xff1a;\u4f9d\u8d56 MySQL \u81ea\u52a8\u6e05\u7406&#xff0c;\u540c\u65f6\u624b\u52a8\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u5927\u5c0f&#xff0c;\u907f\u514d\u78c1\u76d8\u5360\u6ee1&#xff1b;<\/li>\n<li>\u65e5\u5fd7\u5907\u4efd&#xff1a;\u5c06 binlog\u3001\u6162\u67e5\u8be2\u65e5\u5fd7\u5b9a\u671f\u5907\u4efd\u5230\u5bf9\u8c61\u5b58\u50a8&#xff08;\u5982 OSS\u3001S3&#xff09;&#xff0c;\u4fdd\u5b58 30 \u5929\u4ee5\u4e0a&#xff0c;\u7528\u4e8e\u6570\u636e\u6062\u590d&#xff1b;<\/li>\n<li>\u65e5\u5fd7\u76d1\u63a7&#xff1a;\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6\u7684\u5927\u5c0f\u3001\u5199\u5165\u901f\u5ea6\u3001\u78c1\u76d8\u4f7f\u7528\u7387&#xff0c;\u8bbe\u7f6e\u544a\u8b66\u9608\u503c&#xff08;\u5982\u78c1\u76d8\u4f7f\u7528\u7387\u8d85\u8fc7 80% \u544a\u8b66&#xff09;&#xff1b;<\/li>\n<li>\u65e5\u5fd7\u5ba1\u8ba1&#xff1a;\u5b9a\u671f\u5206\u6790 binlog \u548c\u6162\u67e5\u8be2\u65e5\u5fd7&#xff0c;\u6392\u67e5\u8fdd\u89c4\u64cd\u4f5c\u548c\u6027\u80fd\u95ee\u9898&#xff0c;\u5f62\u6210\u5ba1\u8ba1\u62a5\u544a\u3002<\/li>\n<\/ul>\n<h4>3. \u6545\u969c\u6392\u67e5\u6700\u4f73\u5b9e\u8df5<\/h4>\n<ul>\n<li>\u6545\u969c\u6392\u67e5\u987a\u5e8f&#xff1a;\u5148\u770b\u9519\u8bef\u65e5\u5fd7&#xff0c;\u518d\u770b\u5bf9\u5e94\u529f\u80fd\u7684\u65e5\u5fd7&#xff08;\u4e3b\u4ece\u540c\u6b65\u770b binlog &#043; \u4e2d\u7ee7\u65e5\u5fd7&#xff0c;\u6027\u80fd\u95ee\u9898\u770b\u6162\u67e5\u8be2\u65e5\u5fd7&#xff0c;\u6570\u636e\u6062\u590d\u770b binlog&#xff09;&#xff1b;<\/li>\n<li>\u4e3b\u4ece\u540c\u6b65\u6392\u67e5&#xff1a;\u901a\u8fc7SHOW SLAVE STATUS\\\\G;\u5b9a\u4f4d\u95ee\u9898&#xff0c;IO \u7ebf\u7a0b\u5931\u8d25\u770b\u4e3b\u5e93 binlog \u548c\u7f51\u7edc&#xff0c;SQL \u7ebf\u7a0b\u5931\u8d25\u770b\u4e2d\u7ee7\u65e5\u5fd7\u548c\u6570\u636e\u4e00\u81f4\u6027&#xff1b;<\/li>\n<li>\u6570\u636e\u6062\u590d\u6d41\u7a0b&#xff1a;\u5168\u91cf\u5907\u4efd \u2192 binlog \u89e3\u6790 \u2192 \u91cd\u653e SQL \u2192 \u9a8c\u8bc1\u6570\u636e&#xff0c;\u6062\u590d\u540e\u7acb\u5373\u68c0\u67e5\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<h4>4. \u6027\u80fd\u8c03\u4f18\u6700\u4f73\u5b9e\u8df5<\/h4>\n<ul>\n<li>\u6162\u67e5\u8be2\u65e5\u5fd7\u662f\u8c03\u4f18\u5165\u53e3&#xff1a;\u6240\u6709 SQL \u4f18\u5316\u5747\u57fa\u4e8e\u6162\u67e5\u8be2\u65e5\u5fd7&#xff0c;\u4f18\u5148\u4f18\u5316\u6267\u884c\u6b21\u6570\u591a\u3001\u6267\u884c\u65f6\u95f4\u957f\u7684\u6162 SQL&#xff1b;<\/li>\n<li>\u7d22\u5f15\u4f18\u5316&#xff1a;\u6839\u636e\u6162\u67e5\u8be2\u65e5\u5fd7\u4e2d\u7684\u626b\u63cf\u884c\u6570&#xff0c;\u4e3a\u9ad8\u9891\u67e5\u8be2\u5b57\u6bb5\u5efa\u7acb\u7d22\u5f15&#xff0c;\u907f\u514d\u5168\u8868\u626b\u63cf&#xff1b;<\/li>\n<li>binlog \u6027\u80fd\u4f18\u5316&#xff1a;\u5f00\u542fbinlog_cache_size&#xff0c;\u63d0\u5347\u5927\u4e8b\u52a1\u7684 binlog \u5199\u5165\u6027\u80fd&#xff1b;\u907f\u514d\u5927\u4e8b\u52a1&#xff0c;\u51cf\u5c11 binlog \u65e5\u5fd7\u4f53\u79ef\u3002<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<p>MySQL \u7684\u65e5\u5fd7\u4f53\u7cfb\u662f\u5176\u7a33\u5b9a\u6027\u3001\u9ad8\u53ef\u7528\u6027\u3001\u53ef\u6062\u590d\u6027\u7684\u6838\u5fc3\u652f\u6491&#xff0c;\u4e0d\u540c\u65e5\u5fd7\u627f\u62c5\u7740\u4e0d\u540c\u7684\u6838\u5fc3\u804c\u8d23&#xff1a;redo log \u548c undo log \u4fdd\u969c\u4e8b\u52a1 ACID&#xff0c;binlog \u652f\u6491\u4e3b\u4ece\u540c\u6b65\u548c\u6570\u636e\u6062\u590d&#xff0c;\u6162\u67e5\u8be2\u65e5\u5fd7\u662f\u6027\u80fd\u8c03\u4f18\u7684\u5173\u952e&#xff0c;\u9519\u8bef\u65e5\u5fd7\u662f\u6545\u969c\u6392\u67e5\u7684\u7b2c\u4e00\u624b\u8d44\u6599&#xff0c;\u4e2d\u7ee7\u65e5\u5fd7\u662f\u4e3b\u4ece\u540c\u6b65\u7684\u4e2d\u95f4\u6865\u6881\u3002<\/p>\n<p>\u4f5c\u4e3a\u540e\u7aef\u5f00\u53d1\u548c DBA&#xff0c;\u638c\u63e1\u5404\u7c7b\u65e5\u5fd7\u7684\u539f\u7406\u3001\u914d\u7f6e\u3001\u4f7f\u7528\u573a\u666f\u662f\u57fa\u7840&#xff0c;\u800c\u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u5408\u7406\u7684\u65e5\u5fd7\u914d\u7f6e\u3001\u89c4\u8303\u7684\u65e5\u5fd7\u7ba1\u7406\u3001\u9ad8\u6548\u7684\u6545\u969c\u6392\u67e5\u662f\u4fdd\u969c\u6570\u636e\u5e93\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002\u672c\u6587\u603b\u7ed3\u7684\u65e5\u5fd7\u914d\u7f6e\u6700\u4f73\u5b9e\u8df5\u3001\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u548c\u6545\u969c\u6392\u67e5\u601d\u8def&#xff0c;\u53ef\u76f4\u63a5\u5e94\u7528\u4e8e\u751f\u4ea7\u73af\u5883&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u548c DBA \u89c4\u907f\u65e5\u5fd7\u76f8\u5173\u7684\u5e38\u89c1\u95ee\u9898&#xff0c;\u63d0\u5347 MySQL \u670d\u52a1\u7684\u7a33\u5b9a\u6027\u548c\u6027\u80fd\u3002<\/p>\n<p>\u6700\u540e&#xff0c;\u8bb0\u4f4f\u4e00\u4e2a\u6838\u5fc3\u539f\u5219&#xff1a;\u65e5\u5fd7\u662f MySQL \u7684 \u201c\u9ed1\u5323\u5b50\u201d&#xff0c;\u505a\u597d\u65e5\u5fd7\u7684\u914d\u7f6e\u548c\u7ba1\u7406&#xff0c;\u624d\u80fd\u5728\u6545\u969c\u53d1\u751f\u65f6\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3001\u6062\u590d\u6570\u636e&#xff0c;\u5c06\u635f\u5931\u964d\u5230\u6700\u4f4e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u65e5\u5fd7\u4f53\u7cfb&#xff1a;\u5206\u7c7b\u3001\u4f7f\u7528\u573a\u666f\u4e0e\u5b9e\u6218\u89e3\u51b3\u65b9\u6848<br \/>\nMySQL \u7684\u65e5\u5fd7\u4f53\u7cfb\u662f\u5176\u9ad8\u53ef\u7528\u3001\u53ef\u6062\u590d\u3001\u53ef\u76d1\u63a7\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u4e0d\u540c\u65e5\u5fd7\u627f\u62c5\u7740\u6545\u969c\u6062\u590d\u3001\u6570\u636e\u5ba1\u8ba1\u3001\u6027\u80fd\u8c03\u4f18\u3001\u4e3b\u4ece\u540c\u6b65\u7b49\u4e0d\u540c\u6838\u5fc3\u804c\u8d23\u3002\u4f5c\u4e3a\u540e\u7aef\u5f00\u53d1\u548c DBA \u65e5\u5e38\u5de5\u4f5c\u4e2d\u9ad8\u9891\u63a5\u89e6\u7684\u6838\u5fc3\u7ec4\u4ef6&#xff0c;\u638c\u63e1\u5404\u7c7b\u65e5\u5fd7\u7684\u7279\u6027\u3001\u4f7f\u7528\u573a\u666f\u53ca\u95ee\u9898\u89e3\u51b3\u65b9\u6848&#xff0c;\u662f\u4fdd\u969c MySQL \u670d\u52a1\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002\u672c\u6587\u5c06\u4ece MySQL \u6838\u5fc3\u65e5\u5fd7\u5206\u7c7b\u51fa\u53d1&#xff0c;\u9010\u4e00\u8bb2\u89e3\u5176\u539f\u7406\u3001\u9002\u7528\u573a\u666f&#xff0c;\u5e76\u7ed3\u5408\u5b9e\u9645<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[114,100,305,124],"topic":[],"class_list":["post-65990","post","type-post","status-publish","format-standard","hentry","category-server","tag-mysql","tag-100","tag-305","tag-124"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/65990.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"MySQL \u65e5\u5fd7\u4f53\u7cfb&#xff1a;\u5206\u7c7b\u3001\u4f7f\u7528\u573a\u666f\u4e0e\u5b9e\u6218\u89e3\u51b3\u65b9\u6848 MySQL \u7684\u65e5\u5fd7\u4f53\u7cfb\u662f\u5176\u9ad8\u53ef\u7528\u3001\u53ef\u6062\u590d\u3001\u53ef\u76d1\u63a7\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u4e0d\u540c\u65e5\u5fd7\u627f\u62c5\u7740\u6545\u969c\u6062\u590d\u3001\u6570\u636e\u5ba1\u8ba1\u3001\u6027\u80fd\u8c03\u4f18\u3001\u4e3b\u4ece\u540c\u6b65\u7b49\u4e0d\u540c\u6838\u5fc3\u804c\u8d23\u3002\u4f5c\u4e3a\u540e\u7aef\u5f00\u53d1\u548c DBA \u65e5\u5e38\u5de5\u4f5c\u4e2d\u9ad8\u9891\u63a5\u89e6\u7684\u6838\u5fc3\u7ec4\u4ef6&#xff0c;\u638c\u63e1\u5404\u7c7b\u65e5\u5fd7\u7684\u7279\u6027\u3001\u4f7f\u7528\u573a\u666f\u53ca\u95ee\u9898\u89e3\u51b3\u65b9\u6848&#xff0c;\u662f\u4fdd\u969c MySQL \u670d\u52a1\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002\u672c\u6587\u5c06\u4ece MySQL \u6838\u5fc3\u65e5\u5fd7\u5206\u7c7b\u51fa\u53d1&#xff0c;\u9010\u4e00\u8bb2\u89e3\u5176\u539f\u7406\u3001\u9002\u7528\u573a\u666f&#xff0c;\u5e76\u7ed3\u5408\u5b9e\u9645\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/65990.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-25T17:56:46+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65990.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/65990.html\",\"name\":\"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-25T17:56:46+00:00\",\"dateModified\":\"2026-01-25T17:56:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/65990.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/65990.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65990.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/65990.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"MySQL \u65e5\u5fd7\u4f53\u7cfb&#xff1a;\u5206\u7c7b\u3001\u4f7f\u7528\u573a\u666f\u4e0e\u5b9e\u6218\u89e3\u51b3\u65b9\u6848 MySQL \u7684\u65e5\u5fd7\u4f53\u7cfb\u662f\u5176\u9ad8\u53ef\u7528\u3001\u53ef\u6062\u590d\u3001\u53ef\u76d1\u63a7\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u4e0d\u540c\u65e5\u5fd7\u627f\u62c5\u7740\u6545\u969c\u6062\u590d\u3001\u6570\u636e\u5ba1\u8ba1\u3001\u6027\u80fd\u8c03\u4f18\u3001\u4e3b\u4ece\u540c\u6b65\u7b49\u4e0d\u540c\u6838\u5fc3\u804c\u8d23\u3002\u4f5c\u4e3a\u540e\u7aef\u5f00\u53d1\u548c DBA \u65e5\u5e38\u5de5\u4f5c\u4e2d\u9ad8\u9891\u63a5\u89e6\u7684\u6838\u5fc3\u7ec4\u4ef6&#xff0c;\u638c\u63e1\u5404\u7c7b\u65e5\u5fd7\u7684\u7279\u6027\u3001\u4f7f\u7528\u573a\u666f\u53ca\u95ee\u9898\u89e3\u51b3\u65b9\u6848&#xff0c;\u662f\u4fdd\u969c MySQL \u670d\u52a1\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002\u672c\u6587\u5c06\u4ece MySQL \u6838\u5fc3\u65e5\u5fd7\u5206\u7c7b\u51fa\u53d1&#xff0c;\u9010\u4e00\u8bb2\u89e3\u5176\u539f\u7406\u3001\u9002\u7528\u573a\u666f&#xff0c;\u5e76\u7ed3\u5408\u5b9e\u9645","og_url":"https:\/\/www.wsisp.com\/helps\/65990.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-25T17:56:46+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/65990.html","url":"https:\/\/www.wsisp.com\/helps\/65990.html","name":"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-25T17:56:46+00:00","dateModified":"2026-01-25T17:56:46+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/65990.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/65990.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/65990.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6df1\u5165\u7406\u89e3MySQL\u65e5\u5fd7\u7684\u516d\u5927\u6838\u5fc3\u7c7b\u578b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=65990"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65990\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=65990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=65990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=65990"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=65990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}