{"id":7577,"date":"2024-11-14T12:29:16","date_gmt":"2024-11-14T04:29:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7577\/"},"modified":"2024-11-14T12:29:16","modified_gmt":"2024-11-14T04:29:16","slug":"c%e8%af%ad%e8%a8%80%e6%93%8d%e4%bd%9cmysql%e9%81%87%e5%88%b0commands-out-of-sync%e9%94%99%e8%af%af%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7577\/","title":{"rendered":"C\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173103124984753.jpg\" class=\"aligncenter\" title=\"C\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"C\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u64cd\u4f5c\u906d\u9047\u201ccommands out of sync\u201d\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528c\u8bed\u8a00\u64cd\u4f5cmysql\u65f6\uff0c\u6709\u65f6\u4f1a\u9047\u5230\u201ccommands out of sync; you can&#8217;t run this command now\u201d\u7684\u9519\u8bef\u3002\u8be5\u9519\u8bef\u901a\u5e38\u8868\u660e\u7ed3\u679c\u96c6\u6ca1\u6709\u6b63\u786e\u91ca\u653e\uff0c\u5bfc\u81f4\u540e\u7eed\u7684sql\u547d\u4ee4\u65e0\u6cd5\u6267\u884c\u3002<\/p>\n<p>\u901a\u5e38\uff0c\u89e3\u51b3\u6b64\u9519\u8bef\u7684\u65b9\u6cd5\u662f\u5728\u6267\u884c\u67e5\u8be2\u7684\u51fd\u6570\u4e2d\u6dfb\u52a0\u9501\uff0c\u786e\u4fdd\u5728\u4ece\u7ed3\u679c\u96c6\u4e2d\u83b7\u53d6\u6570\u636e\u65f6\u4e0d\u4f1a\u53d1\u751f\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u786e\u4fdd\u5728\u4e0d\u518d\u9700\u8981\u7ed3\u679c\u96c6\u65f6\u5c06\u5176\u91ca\u653e\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u5728\u67e5\u8be2\u51fd\u6570\u4e2d\u6dfb\u52a0\u9501\nstd::lock_guard&lt;std::mutex&gt; lock(result_mutex);\n\n\/\/ \u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c\u96c6\nMYSQL_RES *result = mysql_store_result(mysql);\n\n\/\/ \u83b7\u53d6\u6570\u636e\u5e76\u5904\u7406\nwhile (MYSQL_ROW row = mysql_fetch_row(result)) {\n    \/\/ \u5904\u7406\u6570\u636e\n}\n\n\/\/ \u91ca\u653e\u7ed3\u679c\u96c6\nmysql_free_result(result);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u6dfb\u52a0\u9501\u5e76\u91ca\u653e\u7ed3\u679c\u96c6\uff0c\u53ef\u4ee5\u786e\u4fdd\u7ed3\u679c\u96c6\u5728\u4e0d\u518d\u9700\u8981\u65f6\u88ab\u6b63\u786e\u91ca\u653e\uff0c\u4ece\u800c\u89e3\u51b3\u201ccommands out of sync\u201d\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fC\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u64cd\u4f5c\u906d\u9047\u201ccommands out of sync\u201d\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5 \u5f53\u4f7f\u7528c\u8bed\u8a00\u64cd\u4f5cmysql\u65f6\uff0c\u6709\u65f6\u4f1a\u9047\u5230\u201ccommands out of sync; you can&#8217;t run this command now\u201d\u7684\u9519\u8bef\u3002\u8be5\u9519\u8bef\u901a\u5e38\u8868\u660e\u7ed3\u679c\u96c6\u6ca1\u6709\u6b63\u786e\u91ca\u653e\uff0c\u5bfc\u81f4\u540e\u7eed\u7684sql\u547d\u4ee4\u65e0\u6cd5\u6267\u884c\u3002 \u901a\u5e38\uff0c\u89e3\u51b3\u6b64\u9519\u8bef\u7684\u65b9\u6cd5\u662f\u5728\u6267\u884c\u67e5\u8be2\u7684\u51fd\u6570\u4e2d\u6dfb\u52a0\u9501\uff0c\u786e\u4fdd\u5728\u4ece\u7ed3\u679c\u96c6\u4e2d\u83b7\u53d6\u6570\u636e\u65f6\u4e0d\u4f1a\u53d1\u751f\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u786e\u4fdd\u5728\u4e0d\u518d\u9700\u8981\u7ed3\u679c\u96c6\u65f6\u5c06\u5176\u91ca\u653e\u3002 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u4ee3\u7801\u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u5728\u67e5\u8be2\u51fd\u6570\u4e2d\u6dfb\u52a0\u9501 std::lock_guard&lt;std::mutex&gt; lock(result_mutex); \/\/ \u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c\u96c6 MYSQL_RES *result = mysql_store_result(mysql); \/\/ \u83b7\u53d6\u6570\u636e\u5e76\u5904\u7406 while (MYSQL_ROW row = mysql_fetch_row(result)) { \/\/ \u5904\u7406\u6570\u636e } \/\/ \u91ca\u653e\u7ed3\u679c\u96c6 mysql_free_result(result); \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u6dfb\u52a0\u9501\u5e76\u91ca\u653e\u7ed3\u679c\u96c6\uff0c\u53ef\u4ee5\u786e\u4fdd\u7ed3\u679c\u96c6\u5728\u4e0d\u518d\u9700\u8981\u65f6\u88ab\u6b63\u786e\u91ca\u653e\uff0c\u4ece\u800c\u89e3\u51b3\u201ccommands out of sync\u201d\u9519\u8bef\u3002 \u4ee5\u4e0a\u5c31\u662fC\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7577","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7577"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7577\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}