{"id":75790,"date":"2024-10-16T01:15:16","date_gmt":"2024-10-15T17:15:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/75790\/"},"modified":"2024-10-16T01:15:17","modified_gmt":"2024-10-15T17:15:17","slug":"mysql-%e6%9f%a5%e7%9c%8b%e8%a1%a8%e7%b5%90%e6%a7%8b%e7%9a%84%e5%af%a6%e9%9a%9b%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4%e7%b0%a1%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/75790\/","title":{"rendered":"MySQL \u67e5\u770b\u8868\u7d50\u69cb\u7684\u5be6\u969b\u64cd\u4f5c\u547d\u4ee4\u7c21\u4ecb"},"content":{"rendered":"<h1 id=\"mysql-%e6%9f%a5%e7%9c%8b%e8%a1%a8%e7%b5%90%e6%a7%8b%e7%9a%84%e5%af%a6%e9%9a%9b%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4%e7%b0%a1%e4%bb%8b-EdmbZQXwLs\">MySQL \u67e5\u770b\u8868\u7d50\u69cb\u7684\u5be6\u969b\u64cd\u4f5c\u547d\u4ee4\u7c21\u4ecb<\/h1>\n<p>\u5728\u4f7f\u7528MySQL\u6578\u64da\u5eab\u6642\uff0c\u4e86\u89e3\u8868\u7684\u7d50\u69cb\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u8868\u7d50\u69cb\u5305\u542b\u4e86\u5b57\u6bb5\u540d\u7a31\u3001\u6578\u64da\u985e\u578b\u3001\u7d04\u675f\u689d\u4ef6\u7b49\u4fe1\u606f\uff0c\u9019\u4e9b\u4fe1\u606f\u5c0d\u65bc\u6578\u64da\u7684\u7ba1\u7406\u548c\u67e5\u8a62\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5e7e\u7a2e\u67e5\u770bMySQL\u8868\u7d50\u69cb\u7684\u5be6\u969b\u64cd\u4f5c\u547d\u4ee4\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528MySQL\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"1-%e4%bd%bf%e7%94%a8describe%e5%91%bd%e4%bb%a4-EdmbZQXwLs\">1. \u4f7f\u7528DESCRIBE\u547d\u4ee4<\/h2>\n<p>\u6700\u5e38\u7528\u7684\u67e5\u770b\u8868\u7d50\u69cb\u7684\u547d\u4ee4\u662f<code>DESCRIBE<\/code>\u3002\u9019\u500b\u547d\u4ee4\u53ef\u4ee5\u5feb\u901f\u986f\u793a\u8868\u7684\u6240\u6709\u5b57\u6bb5\u53ca\u5176\u5c6c\u6027\u3002<\/p>\n<pre><code>DESCRIBE \u8868\u540d;\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba<code>users<\/code>\u7684\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5176\u7d50\u69cb\uff1a<\/p>\n<pre><code>DESCRIBE users;\n<\/code><\/pre>\n<p>\u57f7\u884c\u5f8c\uff0c\u5c07\u8fd4\u56de\u985e\u4f3c\u4ee5\u4e0b\u7684\u7d50\u679c\uff1a<\/p>\n<pre><code>Field      | Type         | Null | Key | Default | Extra\n-----------|--------------|------|-----|---------|-------\nid         | int(11)     | NO   | PRI | NULL    | auto_increment\nusername   | varchar(50) | NO   | UNI | NULL    | \npassword   | varchar(255)| NO   |     | NULL    | \ncreated_at | datetime    | NO   |     | NULL    | \n<\/code><\/pre>\n<h2 id=\"2-%e4%bd%bf%e7%94%a8show-columns%e5%91%bd%e4%bb%a4-EdmbZQXwLs\">2. \u4f7f\u7528SHOW COLUMNS\u547d\u4ee4<\/h2>\n<p>\u53e6\u4e00\u500b\u67e5\u770b\u8868\u7d50\u69cb\u7684\u547d\u4ee4\u662f<code>SHOW COLUMNS<\/code>\u3002\u9019\u500b\u547d\u4ee4\u7684\u529f\u80fd\u8207<code>DESCRIBE<\/code>\u985e\u4f3c\uff0c\u4f46\u8fd4\u56de\u7684\u683c\u5f0f\u7a0d\u6709\u4e0d\u540c\u3002<\/p>\n<pre><code>SHOW COLUMNS FROM \u8868\u540d;\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c0d\u65bc<code>users<\/code>\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SHOW COLUMNS FROM users;\n<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u985e\u4f3c\u7684\u7d50\u679c\uff0c\u986f\u793a\u6bcf\u500b\u5b57\u6bb5\u7684\u540d\u7a31\u3001\u985e\u578b\u3001\u662f\u5426\u53ef\u4ee5\u70baNULL\u3001\u9375\u985e\u578b\u3001\u9ed8\u8a8d\u503c\u7b49\u4fe1\u606f\u3002<\/p>\n<h2 id=\"3-%e4%bd%bf%e7%94%a8information_schema-EdmbZQXwLs\">3. \u4f7f\u7528INFORMATION_SCHEMA<\/h2>\n<p>MySQL\u9084\u63d0\u4f9b\u4e86\u4e00\u500b\u540d\u70ba<code>INFORMATION_SCHEMA<\/code>\u7684\u6578\u64da\u5eab\uff0c\u8a72\u6578\u64da\u5eab\u5305\u542b\u4e86\u6240\u6709\u6578\u64da\u5eab\u7684\u5143\u6578\u64da\u3002\u7528\u6236\u53ef\u4ee5\u901a\u904e\u67e5\u8a62\u9019\u500b\u6578\u64da\u5eab\u4f86\u7372\u53d6\u8868\u7684\u7d50\u69cb\u4fe1\u606f\u3002<\/p>\n<pre><code>SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT \nFROM INFORMATION_SCHEMA.COLUMNS \nWHERE TABLE_NAME = '\u8868\u540d' AND TABLE_SCHEMA = '\u6578\u64da\u5eab\u540d';\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u67e5\u8a62<code>users<\/code>\u8868\u7684\u7d50\u69cb\uff1a<\/p>\n<pre><code>SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT \nFROM INFORMATION_SCHEMA.COLUMNS \nWHERE TABLE_NAME = 'users' AND TABLE_SCHEMA = 'your_database_name';\n<\/code><\/pre>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8show-create-table%e5%91%bd%e4%bb%a4-EdmbZQXwLs\">4. \u4f7f\u7528SHOW CREATE TABLE\u547d\u4ee4<\/h2>\n<p>\u5982\u679c\u9700\u8981\u67e5\u770b\u8868\u7684\u5275\u5efa\u8a9e\u53e5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>SHOW CREATE TABLE<\/code>\u547d\u4ee4\u3002\u9019\u500b\u547d\u4ee4\u5c07\u986f\u793a\u5275\u5efa\u8868\u7684\u5b8c\u6574SQL\u8a9e\u53e5\uff0c\u5305\u62ec\u6240\u6709\u7684\u7d04\u675f\u548c\u7d22\u5f15\u3002<\/p>\n<pre><code>SHOW CREATE TABLE \u8868\u540d;\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>SHOW CREATE TABLE users;\n<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u985e\u4f3c\u4ee5\u4e0b\u7684\u7d50\u679c\uff1a<\/p>\n<pre><code>Table: users\nCreate Table: CREATE TABLE `users` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `username` varchar(50) NOT NULL,\n  `password` varchar(255) NOT NULL,\n  `created_at` datetime NOT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `username` (`username`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-EdmbZQXwLs\">\u7e3d\u7d50<\/h2>\n<p>\u4e86\u89e3\u5982\u4f55\u67e5\u770bMySQL\u8868\u7d50\u69cb\u662f\u6578\u64da\u5eab\u7ba1\u7406\u7684\u91cd\u8981\u4e00\u74b0\u3002\u901a\u904e\u4f7f\u7528<code>DESCRIBE<\/code>\u3001<code>SHOW COLUMNS<\/code>\u3001<code>INFORMATION_SCHEMA<\/code>\u548c<code>SHOW CREATE TABLE<\/code>\u7b49\u547d\u4ee4\uff0c\u7528\u6236\u53ef\u4ee5\u8f15\u9b06\u7372\u53d6\u6240\u9700\u7684\u8868\u7d50\u69cb\u4fe1\u606f\u3002\u9019\u4e9b\u547d\u4ee4\u4e0d\u50c5\u80fd\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u7406\u89e3\u6578\u64da\u5eab\u7684\u8a2d\u8a08\uff0c\u9084\u80fd\u5728\u9032\u884c\u6578\u64da\u64cd\u4f5c\u6642\u63d0\u4f9b\u5fc5\u8981\u7684\u652f\u6301\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u7528\u6236\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 MySQL \u547d\u4ee4\u67e5\u770b\u8868\u7d50\u69cb\uff0c\u638c\u63e1\u5be6\u969b\u64cd\u4f5c\u6280\u5de7\uff0c\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-75790","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75790","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=75790"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75790\/revisions"}],"predecessor-version":[{"id":75791,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75790\/revisions\/75791"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=75790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=75790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=75790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}