{"id":5490,"date":"2024-11-14T11:28:52","date_gmt":"2024-11-14T03:28:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5490\/"},"modified":"2024-11-14T11:28:52","modified_gmt":"2024-11-14T03:28:52","slug":"mysql%e5%8f%98%e9%87%8f%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5490\/","title":{"rendered":"mysql\u53d8\u91cf\u600e\u4e48\u4f7f\u7528"},"content":{"rendered":"<blockquote><p>\n  mysql \u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u4f1a\u8bdd\u6570\u636e\uff0c\u521b\u5efa\u65f6\u4ee5 @ \u7b26\u53f7\u5f00\u5934\uff0c\u53ef\u5b58\u50a8\u591a\u79cd\u7c7b\u578b\u7684\u503c\uff0c\u5305\u62ec\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u65e5\u671f\u548c\u5e03\u5c14\u503c\u3002\u6b64\u5916\uff0cmysql \u8fd8\u63d0\u4f9b\u5185\u7f6e\u53d8\u91cf\uff0c\u5b58\u50a8\u6709\u5173\u4f1a\u8bdd\u3001\u8fde\u63a5\u548c\u670d\u52a1\u5668\u7684\u4fe1\u606f\u3002\u8fd9\u4e9b\u53d8\u91cf\u4ec5\u5728\u4f1a\u8bdd\u671f\u95f4\u5b58\u5728\uff0c\u8fde\u63a5\u7ed3\u675f\u540e\u5c06\u4e22\u5931\uff0c\u5e76\u4e14\u53d8\u91cf\u540d\u79f0\u533a\u5206\u5927\u5c0f\u5199\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052904152233716.jpg\" class=\"aligncenter\" title=\"mysql\u53d8\u91cf\u600e\u4e48\u4f7f\u7528\u63d2\u56fe\" alt=\"mysql\u53d8\u91cf\u600e\u4e48\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<h2>MySQL \u53d8\u91cf\u7684\u4f7f\u7528<\/h2>\n<p>\u5728 MySQL \u4e2d\uff0c\u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u4f1a\u8bdd\u671f\u95f4\u7684\u503c\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b58\u50a8\u548c\u4f7f\u7528\u4e34\u65f6\u6570\u636e\u3001\u81ea\u5b9a\u4e49\u67e5\u8be2\u6216\u8ddf\u8e2a\u4fe1\u606f\u3002<\/p>\n<h3>\u521b\u5efa\u548c\u8d4b\u503c<\/h3>\n<p>\u4f7f\u7528 SET \u8bed\u53e5\u521b\u5efa\u548c\u8d4b\u503c\u53d8\u91cf\uff1a<\/p>\n<pre>SET @variable_name = value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53d8\u91cf\u540d\u79f0\u4ee5 @ \u7b26\u53f7\u5f00\u5934\uff0c\u540e\u9762\u8ddf\u5b9e\u9645\u7684\u53d8\u91cf\u540d\u79f0\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a @count \u7684\u53d8\u91cf\u5e76\u5c06\u5176\u8d4b\u503c\u4e3a 5\uff1a<\/p>\n<pre>SET @count = 5;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u4f7f\u7528<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528\u53d8\u91cf\u540d\u79f0\u5f15\u7528\u53d8\u91cf\u7684\u503c\uff0c\u4f8b\u5982\u5728\u67e5\u8be2\u6216\u8ba1\u7b97\u4e2d\uff1a<\/p>\n<pre>SELECT * FROM table WHERE id &gt; @count;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528 SET \u8bed\u53e5\u66f4\u65b0\u53d8\u91cf\u7684\u503c\uff1a<\/p>\n<pre>SET @count = @count + 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u7c7b\u578b<\/h3>\n<p>MySQL \u53d8\u91cf\u53ef\u4ee5\u5b58\u50a8\u591a\u79cd\u7c7b\u578b\u7684\u503c\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6570\u5b57 (INT, FLOAT)<\/li>\n<li>\u5b57\u7b26\u4e32 (VARCHAR, TEXT)<\/li>\n<li>\u65e5\u671f\u548c\u65f6\u95f4 (DATE, DATETIME)<\/li>\n<li>\u5e03\u5c14\u503c (BOOL)<\/li>\n<\/ul>\n<p>MySQL \u53d8\u91cf\u7684\u7c7b\u578b\u53d6\u51b3\u4e8e\u5b58\u50a8\u7684\u503c\u7684\u7c7b\u578b\u3002<\/p>\n<h3>\u5185\u7f6e\u53d8\u91cf<\/h3>\n<p>\u9664\u4e86\u7528\u6237\u5b9a\u4e49\u7684\u53d8\u91cf\uff0cMySQL \u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u53d8\u91cf\uff0c\u5b58\u50a8\u6709\u5173\u4f1a\u8bdd\u3001\u8fde\u63a5\u548c\u670d\u52a1\u5668\u7684\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>@@version\uff1aMySQL \u670d\u52a1\u5668\u7248\u672c<\/li>\n<li>@@datadir\uff1a\u6570\u636e\u76ee\u5f55\u8def\u5f84<\/li>\n<li>@@hostname\uff1a\u670d\u52a1\u5668\u4e3b\u673a\u540d<\/li>\n<li>@@user\uff1a\u5f53\u524d\u8fde\u63a5\u7684\u7528\u6237<\/li>\n<\/ul>\n<h3>\u6ce8\u610f<\/h3>\n<ul>\n<li>\u53d8\u91cf\u4ec5\u5728\u4f1a\u8bdd\u671f\u95f4\u5b58\u5728\uff0c\u8fde\u63a5\u7ed3\u675f\u540e\u5c06\u4e22\u5931\u3002<\/li>\n<li>\u53d8\u91cf\u540d\u79f0\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<li>\u53d8\u91cf\u503c\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u8868\u8fbe\u5f0f\u6216\u5176\u4ed6\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u53d8\u91cf\u600e\u4e48\u4f7f\u7528\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>mysql \u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u4f1a\u8bdd\u6570\u636e\uff0c\u521b\u5efa\u65f6\u4ee5 @ \u7b26\u53f7\u5f00\u5934\uff0c\u53ef\u5b58\u50a8\u591a\u79cd\u7c7b\u578b\u7684\u503c\uff0c\u5305\u62ec\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u65e5\u671f\u548c\u5e03\u5c14\u503c\u3002\u6b64\u5916\uff0cmysql \u8fd8\u63d0\u4f9b\u5185\u7f6e\u53d8\u91cf\uff0c\u5b58\u50a8\u6709\u5173\u4f1a\u8bdd\u3001\u8fde\u63a5\u548c\u670d\u52a1\u5668\u7684\u4fe1\u606f\u3002\u8fd9\u4e9b\u53d8\u91cf\u4ec5\u5728\u4f1a\u8bdd\u671f\u95f4\u5b58\u5728\uff0c\u8fde\u63a5\u7ed3\u675f\u540e\u5c06\u4e22\u5931\uff0c\u5e76\u4e14\u53d8\u91cf\u540d\u79f0\u533a\u5206\u5927\u5c0f\u5199\u3002 MySQL \u53d8\u91cf\u7684\u4f7f\u7528 \u5728 MySQL \u4e2d\uff0c\u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u4f1a\u8bdd\u671f\u95f4\u7684\u503c\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b58\u50a8\u548c\u4f7f\u7528\u4e34\u65f6\u6570\u636e\u3001\u81ea\u5b9a\u4e49\u67e5\u8be2\u6216\u8ddf\u8e2a\u4fe1\u606f\u3002 \u521b\u5efa\u548c\u8d4b\u503c \u4f7f\u7528 SET \u8bed\u53e5\u521b\u5efa\u548c\u8d4b\u503c\u53d8\u91cf\uff1a SET @variable_name = value; \u767b\u5f55\u540e\u590d\u5236 \u53d8\u91cf\u540d\u79f0\u4ee5 @ \u7b26\u53f7\u5f00\u5934\uff0c\u540e\u9762\u8ddf\u5b9e\u9645\u7684\u53d8\u91cf\u540d\u79f0\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a @count \u7684\u53d8\u91cf\u5e76\u5c06\u5176\u8d4b\u503c\u4e3a 5\uff1a SET @count = 5; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 \u53ef\u4ee5\u4f7f\u7528\u53d8\u91cf\u540d\u79f0\u5f15\u7528\u53d8\u91cf\u7684\u503c\uff0c\u4f8b\u5982\u5728\u67e5\u8be2\u6216\u8ba1\u7b97\u4e2d\uff1a SELECT * FROM table WHERE id &gt; @count; \u767b\u5f55\u540e\u590d\u5236 \u4e5f\u53ef\u4ee5\u4f7f\u7528 SET \u8bed\u53e5\u66f4\u65b0\u53d8\u91cf\u7684\u503c\uff1a SET @count = @count + 1; \u767b\u5f55\u540e\u590d\u5236 \u7c7b\u578b MySQL \u53d8\u91cf\u53ef\u4ee5\u5b58\u50a8\u591a\u79cd\u7c7b\u578b\u7684\u503c\uff0c\u5305\u62ec\uff1a \u6570\u5b57 [&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-5490","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5490","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=5490"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5490\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}