{"id":26697,"date":"2024-11-24T11:59:18","date_gmt":"2024-11-24T03:59:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26697\/"},"modified":"2024-11-24T11:59:18","modified_gmt":"2024-11-24T03:59:18","slug":"c%e8%af%ad%e8%a8%80%e6%93%8d%e4%bd%9cmysql%e6%97%b6%e5%87%ba%e7%8e%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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26697\/","title":{"rendered":"C\u8bed\u8a00\u64cd\u4f5cMySQL\u65f6\u51fa\u73b0\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\/173104776468247.jpg\" class=\"aligncenter\" title=\"C\u8bed\u8a00\u64cd\u4f5cMySQL\u65f6\u51fa\u73b0\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"C\u8bed\u8a00\u64cd\u4f5cMySQL\u65f6\u51fa\u73b0\u201cCommands out of sync\u201d\u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u64cd\u4f5c\u65f6\u9047\u5230\u201ccommands out of sync; you can&#8217;t run this command now\u201d\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728c\u8bed\u8a00\u4e2d\u64cd\u4f5cmysql\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u201ccommands out of sync; you can&#8217;t run this command now\u201d\u9519\u8bef\uff0c\u901a\u5e38\u662f\u56e0\u4e3a\u5728\u672a\u91ca\u653e\u4e0a\u4e00\u4e2a\u7ed3\u679c\u96c6\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u4e86\u540e\u7eed\u7684\u6240\u81f4\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u91ca\u653e\u7ed3\u679c\u96c6\uff1a<\/strong>\u5728\u6267\u884c\u4e0b\u4e00\u6b21sql\u8bed\u53e5\u4e4b\u524d\uff0c\u5fc5\u987b\u5148\u91ca\u653e\u4e0a\u4e00\u4e2a\u7ed3\u679c\u96c6\u3002\u53ef\u4ee5\u4f7f\u7528mysql_free_result()\u51fd\u6570\u6765\u91ca\u653e\u7ed3\u679c\u96c6\u3002<\/li>\n<li> <strong>\u68c0\u67e5\u6570\u636e\u5e93\u8fde\u63a5\uff1a<\/strong>\u786e\u4fdd\u6570\u636e\u5e93\u8fde\u63a5\u5df2\u6b63\u786e\u5efa\u7acb\u4e14\u672a\u65ad\u5f00\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u67e5\u8be2\u9501\uff1a<\/strong>\u5728\u8fdb\u884c\u540c\u65f6\u8bfb\u5199\u64cd\u4f5c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u67e5\u8be2\u9501\u6765\u9632\u6b62\u5e76\u53d1\u64cd\u4f5c\u51b2\u7a81\u3002\u53ef\u4ee5\u5728\u6267\u884c\u67e5\u8be2\u8bed\u53e5\u524d\u4f7f\u7528mysql_lock_tables()\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u83b7\u53d6\u7ed3\u679c\u96c6\nMYSQL_RES *result = mysql_store_result(mysql);\n\n\/\/ \u5904\u7406\u7ed3\u679c\u96c6\nwhile ((row = mysql_fetch_row(result)) != NULL) {\n    \/\/ \u5904\u7406\u884c\u6570\u636e\n}\n\n\/\/ \u91ca\u653e\u7ed3\u679c\u96c6\nmysql_free_result(result);\n\n\/\/ \u6267\u884c\u540e\u7eed SQL \u8bed\u53e5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5728\u7a0b\u5e8f\u9000\u51fa\u6216\u9500\u6bc1\u6570\u636e\u5e93\u8fde\u63a5\u65f6\uff0c\u91ca\u653e\u6240\u6709\u5df2\u6253\u5f00\u7684\u7ed3\u679c\u96c6\u3002<\/li>\n<li>\u5982\u679c\u4ecd\u7136\u9047\u5230\u8be5\u9519\u8bef\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u65b0\u542f\u52a8mysql\u670d\u52a1\u5668\u6216\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u7a33\u5b9a\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fC\u8bed\u8a00\u64cd\u4f5cMySQL\u65f6\u51fa\u73b0\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\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u64cd\u4f5c\u65f6\u9047\u5230\u201ccommands out of sync; you can&#8217;t run this command now\u201d\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5 \u5728c\u8bed\u8a00\u4e2d\u64cd\u4f5cmysql\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u201ccommands out of sync; you can&#8217;t run this command now\u201d\u9519\u8bef\uff0c\u901a\u5e38\u662f\u56e0\u4e3a\u5728\u672a\u91ca\u653e\u4e0a\u4e00\u4e2a\u7ed3\u679c\u96c6\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u4e86\u540e\u7eed\u7684\u6240\u81f4\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u91ca\u653e\u7ed3\u679c\u96c6\uff1a\u5728\u6267\u884c\u4e0b\u4e00\u6b21sql\u8bed\u53e5\u4e4b\u524d\uff0c\u5fc5\u987b\u5148\u91ca\u653e\u4e0a\u4e00\u4e2a\u7ed3\u679c\u96c6\u3002\u53ef\u4ee5\u4f7f\u7528mysql_free_result()\u51fd\u6570\u6765\u91ca\u653e\u7ed3\u679c\u96c6\u3002 \u68c0\u67e5\u6570\u636e\u5e93\u8fde\u63a5\uff1a\u786e\u4fdd\u6570\u636e\u5e93\u8fde\u63a5\u5df2\u6b63\u786e\u5efa\u7acb\u4e14\u672a\u65ad\u5f00\u3002 \u4f7f\u7528\u67e5\u8be2\u9501\uff1a\u5728\u8fdb\u884c\u540c\u65f6\u8bfb\u5199\u64cd\u4f5c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u67e5\u8be2\u9501\u6765\u9632\u6b62\u5e76\u53d1\u64cd\u4f5c\u51b2\u7a81\u3002\u53ef\u4ee5\u5728\u6267\u884c\u67e5\u8be2\u8bed\u53e5\u524d\u4f7f\u7528mysql_lock_tables()\u51fd\u6570\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u83b7\u53d6\u7ed3\u679c\u96c6 MYSQL_RES *result = mysql_store_result(mysql); \/\/ \u5904\u7406\u7ed3\u679c\u96c6 while ((row = mysql_fetch_row(result)) != NULL) { \/\/ \u5904\u7406\u884c\u6570\u636e } \/\/ \u91ca\u653e\u7ed3\u679c\u96c6 mysql_free_result(result); \/\/ \u6267\u884c\u540e\u7eed SQL \u8bed\u53e5 \u767b\u5f55\u540e\u590d\u5236 \u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a \u786e\u4fdd\u5728\u7a0b\u5e8f\u9000\u51fa\u6216\u9500\u6bc1\u6570\u636e\u5e93\u8fde\u63a5\u65f6\uff0c\u91ca\u653e\u6240\u6709\u5df2\u6253\u5f00\u7684\u7ed3\u679c\u96c6\u3002 \u5982\u679c\u4ecd\u7136\u9047\u5230\u8be5\u9519\u8bef\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u65b0\u542f\u52a8mysql\u670d\u52a1\u5668\u6216\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u7a33\u5b9a\u3002 [&hellip;]<\/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-26697","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26697","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=26697"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26697\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}