{"id":2253,"date":"2015-06-13T22:53:25","date_gmt":"2015-06-13T14:53:25","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2253"},"modified":"2015-06-13T22:53:25","modified_gmt":"2015-06-13T14:53:25","slug":"mysql%e4%b8%ad%e7%9a%84%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2253.html","title":{"rendered":"MySQL\u4e2d\u7684\u53d8\u91cf"},"content":{"rendered":"<p><strong>MySQL<\/strong><strong>\u4e2d\u7684\u53d8\u91cf<\/strong>\u5206\u4e3a<span style=\"color: #0000ff;\"><strong>\u7528\u6237\u53d8\u91cf<\/strong><\/span>\u4e0e<span style=\"color: #ff0000;\"><strong>\u7cfb\u7edf\u53d8\u91cf<\/strong><\/span>\u3002<\/p>\n<h5>\u7528\u6237\u53d8\u91cf\uff1a<\/h5>\n<p>\u7528\u6237\u53d8\u91cf\u4e0e\u6570\u636e\u5e93\u8fde\u63a5\u6709\u5173\uff0c\u5728\u8fd9\u4e2a\u8fde\u63a5\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u5728\u8fde\u63a5\u65ad\u5f00\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u6d88\u5931\uff1b\u5728\u6b64\u8fde\u63a5\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\u65e0\u6cd5\u5728\u53e6\u4e00\u8fde\u63a5\u4e2d\u4f7f\u7528\uff1b\u7528\u6237\u53d8\u91cf\u7684\u53d8\u91cf\u540d\u7684\u5f62\u5f0f\u4e3a @varname \u7684\u5f62\u5f0f\uff0c\u540d\u5b57\u5fc5\u987b\u4ee5@\u5f00\u5934\u3002<\/p>\n<p>\u58f0\u660e\u53d8\u91cf\u7684\u65f6\u5019\u9700\u8981\u4f7f\u7528 set \u8bed\u53e5\uff0c\u6bd4\u5982\u4e0b\u9762\u7684\u8bed\u53e5\u58f0\u660e\u4e86\u4e00\u4e2a\u540d\u4e3a @a \u7684\u53d8\u91cf\u3002<\/p>\n<pre class=\"lang:default decode:true\">set @a = 1;<\/pre>\n<p>\u58f0\u660e\u4e00\u4e2a\u540d\u4e3a@a\u7684\u53d8\u91cf\uff0c\u5e76\u5c06\u5b83\u8d4b\u503c\u4e3a1\uff0c<span style=\"color: #ff0000;\">MySQL\u91cc\u9762\u7684\u53d8\u91cf\u662f\u4e0d\u4e25\u683c\u9650\u5236\u6570\u636e\u7c7b\u578b\u7684\uff0c\u5b83\u7684\u6570\u636e\u7c7b\u578b\u6839\u636e\u4f60\u8d4b\u7ed9\u5b83\u7684\u503c\u800c\u968f\u65f6\u53d8\u5316<\/span>\u3002{SQL SERVER\u4e2d\u4f7f\u7528declare\u8bed\u53e5\u58f0\u660e\u53d8\u91cf\uff0c\u4e14\u4e25\u683c\u9650\u5236\u6570\u636e\u7c7b\u578b\u3002}<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 select \u8bed\u53e5\u4e3a\u53d8\u91cf\u8d4b\u503c\u3002<\/p>\n<p>\u6bd4\u5982\uff1a<\/p>\n<pre class=\"lang:default decode:true\">select @name:=user from mysql.user limit 0,1;\n\/* \u6ce8\u610f\u7b49\u4e8e\u53f7\u524d\u9762\u6709\u4e00\u4e2a\u5192\u53f7\uff0c\u540e\u9762\u7684limit 0,1\u662f\u7528\u6765\u9650\u5236\u8fd4\u56de\u7ed3\u679c\u7684\uff0c\u76f8\u5f53\u4e8eSQL SERVER\u91cc\u9762\u7684top 1 *\/<\/pre>\n<p>\u5982\u679c\u76f4\u63a5\u5199\uff1a<\/p>\n<pre class=\"lang:default decode:true\">select @name:=user from mysql.user;<\/pre>\n<p>\u5982\u679c\u8fd9\u4e2a\u67e5\u8be2\u8fd4\u56de\u591a\u4e2a\u503c\u7684\u8bdd\uff0c\u90a3 @name \u53d8\u91cf\u7684\u503c\u5c31\u662f\u6700\u540e\u4e00\u6761\u8bb0\u5f55\u7684 user \u5b57\u6bb5\u7684\u503c\u3002<\/p>\n<h5>\u7cfb\u7edf\u53d8\u91cf\uff1a<\/h5>\n<p>\u7cfb\u7edf\u53d8\u91cf\u53c8\u5206\u4e3a<strong>\u5168\u5c40\u53d8\u91cf(global variables)<\/strong>\u4e0e<strong>\u4f1a\u8bdd\u53d8\u91cf(session variables)<\/strong>\u3002<\/p>\n<p>\u5168\u5c40\u53d8\u91cf\u5728MySQL\u542f\u52a8\u7684\u65f6\u5019\u7531\u670d\u52a1\u5668\u81ea\u52a8\u5c06\u5b83\u4eec\u521d\u59cb\u5316\u4e3a\u9ed8\u8ba4\u503c\uff0c\u8fd9\u4e9b\u9ed8\u8ba4\u503c\u53ef\u4ee5\u901a\u8fc7\u66f4\u6539 my.ini \u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u6765\u66f4\u6539\u3002<\/p>\n<p>\u4f1a\u8bdd\u53d8\u91cf\u5728\u6bcf\u6b21\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u8fde\u63a5\u7684\u65f6\u5019\uff0c\u7531MySQL\u6765\u521d\u59cb\u5316\u3002MySQL\u4f1a\u5c06\u5f53\u524d\u6240\u6709\u5168\u5c40\u53d8\u91cf\u7684\u503c\u590d\u5236\u4e00\u4efd\u3002\u6765\u505a\u4e3a\u4f1a\u8bdd\u53d8\u91cf\u3002{\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5728\u5efa\u7acb\u4f1a\u8bdd\u4ee5\u540e\uff0c\u6ca1\u6709\u624b\u52a8\u66f4\u6539\u8fc7\u4f1a\u8bdd\u53d8\u91cf\u4e0e\u5168\u5c40\u53d8\u91cf\u7684\u503c\uff0c\u90a3\u6240\u6709\u8fd9\u4e9b\u53d8\u91cf\u7684\u503c\u90fd\u662f\u4e00\u6837\u7684\u3002}<\/p>\n<p>\u5168\u5c40\u53d8\u91cf\u4e0e\u4f1a\u8bdd\u53d8\u91cf\u7684\u533a\u522b\u5c31\u5728\u4e8e\uff0c\u5bf9\u5168\u5c40\u53d8\u91cf\u7684\u4fee\u6539\u4f1a\u5f71\u54cd\u5230\u6574\u4e2a\u670d\u52a1\u5668\uff0c\u4f46\u662f\u5bf9\u4f1a\u8bdd\u53d8\u91cf\u7684\u4fee\u6539\uff0c\u53ea\u4f1a\u5f71\u54cd\u5230\u5f53\u524d\u7684\u4f1a\u8bdd\u3002<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/server-system-variables.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/server-system-variables.html<\/a><\/li>\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/show-variables.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/show-variables.html<\/a><\/li>\n<li><a href=\"http:\/\/blog.knowsky.com\/252519.htm\">http:\/\/blog.knowsky.com\/252519.htm<\/a><\/li>\n<li><a href=\"http:\/\/doc.mysql.cn\/mysql5\/refman-5.1-zh.html-chapter\/language-structure.html#variables\">http:\/\/doc.mysql.cn\/mysql5\/refman-5.1-zh.html-chapter\/language-structure.html#variables<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/www.mysqlab.net\/docs\/view\/refman-5.1-zh\/chapter\/index.html\">http:\/\/www.mysqlab.net\/docs\/view\/refman-5.1-zh\/chapter\/index.html<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/1009954\/mysql-variable-vs-variable-whats-the-difference\">http:\/\/stackoverflow.com\/questions\/1009954\/mysql-variable-vs-variable-whats-the-difference<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/www.thegeekstuff.com\/2013\/09\/mysql-select-command\/\">http:\/\/www.thegeekstuff.com\/2013\/09\/mysql-select-command\/<\/a><\/li>\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/select.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/select.html<\/a><\/li>\n<\/ul>\n<h6>\u4e00\u4e9bMySQL\u8bed\u53e5\uff1a<\/h6>\n<pre class=\"lang:default decode:true \">&gt; show databases;\n&gt; select host,user,password from mysql.user;\n&gt; show processlist;\n&gt; show [global|session] variables;\n&gt; show variables like '%dir';\n&gt; show variables like 'version%';<\/pre>\n<p>&amp;<\/p>\n<pre class=\"lang:default decode:true\">&gt; select version_compile_os;\nERROR 1054 (42S22): Unknown column 'version_compile_os' in 'field list'\n&gt; select @version_compile_os;\n+---------------------+\n| @version_compile_os |\n+---------------------+\n| NULL                |\n+---------------------+\n1 row in set (0.00 sec)\n\n&gt; select @@version_compile_os;\n+----------------------+\n| @@version_compile_os |\n+----------------------+\n| Linux                |\n+----------------------+\n1 row in set (0.00 sec)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u4e2d\u7684\u53d8\u91cf\u5206\u4e3a\u7528\u6237\u53d8\u91cf\u4e0e\u7cfb\u7edf\u53d8\u91cf\u3002 \u7528\u6237\u53d8\u91cf\uff1a \u7528\u6237\u53d8\u91cf\u4e0e\u6570\u636e\u5e93\u8fde\u63a5\u6709\u5173\uff0c\u5728\u8fd9\u4e2a\u8fde\u63a5\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u5728\u8fde [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23],"tags":[16],"class_list":["post-2253","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","tag-mysql"],"views":3237,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2253"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2253\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}