{"id":5461,"date":"2024-11-14T12:44:17","date_gmt":"2024-11-14T04:44:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5461\/"},"modified":"2024-11-14T12:44:17","modified_gmt":"2024-11-14T04:44:17","slug":"mysql%e6%80%8e%e4%b9%88%e6%9f%a5%e7%9c%8b%e8%a1%a8%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5461\/","title":{"rendered":"mysql\u600e\u4e48\u67e5\u770b\u8868\u7ed3\u6784"},"content":{"rendered":"<blockquote><p>\n  \u67e5\u770b mysql \u8868\u7ed3\u6784\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 describe \u547d\u4ee4\uff1adescribe table_name;\u4f7f\u7528 information_schema.columns \u8868\uff1aselect * from information_schema.columns where table_name = &#8216;table_name&#8217;;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052815062146041.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u67e5\u770b\u8868\u7ed3\u6784\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u67e5\u770b\u8868\u7ed3\u6784\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u770b\u8868\u7ed3\u6784<\/strong><\/p>\n<p>\u67e5\u770b MySQL \u8868\u7ed3\u6784\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u4e24\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528 DESCRIBE \u547d\u4ee4<\/strong><\/p>\n<pre>DESCRIBE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 INFORMATION_SCHEMA.COLUMNS \u8868<\/strong><\/p>\n<pre>SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'table_name';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c\u89e3\u8bfb<\/strong><\/p>\n<p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u7ed3\u679c\u90fd\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u793a\u4f8b\uff1a<\/p>\n<pre>| Field | Type | Null | Key | Default | Extra |\n|---|---|---|---|---|---|\n| id | int | NO | PRI | NULL | auto_increment |\n| name | varchar(255) | YES | | NULL | |\n| age | int | YES | | NULL | |<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8bf4\u660e<\/strong>\uff1a<\/p>\n<ul>\n<li> <strong>Field\uff1a<\/strong>\u8868\u7684\u5217\u540d<\/li>\n<li> <strong>Type\uff1a<\/strong>\u5217\u7684\u6570\u636e\u7c7b\u578b<\/li>\n<li> <strong>Null\uff1a<\/strong>\u662f\u5426\u5141\u8bb8 NULL \u503c\uff08YES\/NO\uff09<\/li>\n<li> <strong>Key\uff1a<\/strong>\u5217\u662f\u5426\u662f\u4e3b\u952e\u6216\u5916\u952e\uff08PRI\/MUL\/UNI\/FOR\uff09<\/li>\n<li> <strong>Default\uff1a<\/strong>\u5217\u7684\u9ed8\u8ba4\u503c<\/li>\n<li> <strong>Extra\uff1a<\/strong>\u6709\u5173\u5217\u7684\u989d\u5916\u4fe1\u606f\uff08\u5982 auto_increment\uff09<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u67e5\u770b\u540d\u4e3a &#8220;users&#8221; \u7684\u8868\u7684\u7ed3\u6784\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>DESCRIBE users;\n\n-- \u6216 --\n\nSELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'users';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u770b\u8868\u7ed3\u6784\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>\u67e5\u770b mysql \u8868\u7ed3\u6784\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 describe \u547d\u4ee4\uff1adescribe table_name;\u4f7f\u7528 information_schema.columns \u8868\uff1aselect * from information_schema.columns where table_name = &#8216;table_name&#8217;; \u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u770b\u8868\u7ed3\u6784 \u67e5\u770b MySQL \u8868\u7ed3\u6784\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u4e24\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a 1. \u4f7f\u7528 DESCRIBE \u547d\u4ee4 DESCRIBE table_name; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 INFORMATION_SCHEMA.COLUMNS \u8868 SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = &#8216;table_name&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u7ed3\u679c\u89e3\u8bfb \u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u7ed3\u679c\u90fd\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u793a\u4f8b\uff1a | Field | Type | Null | Key | Default | Extra [&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-5461","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5461","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=5461"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5461\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}