{"id":201021,"date":"2025-05-06T08:08:21","date_gmt":"2025-05-06T00:08:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201021\/"},"modified":"2025-05-06T08:08:21","modified_gmt":"2025-05-06T00:08:21","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:\/\/server.hk\/cnblog\/201021\/","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><b><\/b> <\/p>\n<h1>C\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u6765\u5230\u4e3b\u673a\u5b9d\u8d1d\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6570\u636e\u5e93\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aC\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241125\/1732540549674478858ed2c.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>c\u8bed\u8a00\u64cd\u4f5cmysql\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\u5e76\u53d1\u8bbf\u95ee\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<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>\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>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6570\u636e\u5e93\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>C\u8bed\u8a00\u64cd\u4f5cMySQL\u9047\u5230\u201cCom&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201021","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201021"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201021\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}