{"id":682,"date":"2024-06-05T20:38:58","date_gmt":"2024-06-05T12:38:58","guid":{"rendered":"https:\/\/cn.raksmart.com\/blog\/host\/4270.html"},"modified":"2024-06-05T20:38:58","modified_gmt":"2024-06-05T12:38:58","slug":"mysql%e6%95%99%e7%a8%8b%ef%bc%882%ef%bc%89","status":"publish","type":"post","link":"https:\/\/cn.raksmart.com\/blog\/knowledge\/682.html","title":{"rendered":"Mysql\u6559\u7a0b\uff082\uff09"},"content":{"rendered":"<div class=\"entry-content e-content\" itemprop=\"description articleBody\">\n<p>\u4eca\u5929\u7684\u5e16\u5b50\uff0c\u6211\u4eec\u5c06\u7ee7\u7eed\u56f4\u7ed5<a href=\"https:\/\/www.raksmart.com\/cps\/7921\" target=\"_blank\" rel=\"noopener\">Mysql<\/a>\u6570\u636e\u5e93\u5c55\u5f00\u5185\u5bb9\uff0c\u63a5\u4e0b\u6765\u4e00\u8d77\u548cRaksmart<strong><a href=\"https:\/\/cn.raksmart.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"\u7f8e\u56fd\u670d\u52a1\u5668\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">\u7f8e\u56fd\u670d\u52a1\u5668<\/a><\/strong>\u5c0f\u7f16\u6765\u770b\u770b\u76f8\u5173\u7684\u5185\u5bb9\u5427\u3002<\/p>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u8868<\/p>\n<p>\u4f7f\u7528 create table \u8bed\u53e5\u53ef\u5b8c\u6210\u5bf9\u8868\u7684\u521b\u5efa, create table \u7684\u5e38\u89c1\u5f62\u5f0f:<\/p>\n<p>create table \u8868\u540d\u79f0(\u5217\u58f0\u660e);<\/p>\n<p>\u4ee5\u521b\u5efa students \u8868\u4e3a\u4f8b, \u8868\u4e2d\u5c06\u5b58\u653e \u5b66\u53f7(id)\u3001\u59d3\u540d(name)\u3001\u6027\u522b(sex)\u3001\u5e74\u9f84(age)\u3001\u8054\u7cfb\u7535\u8bdd(tel) \u8fd9\u4e9b\u5185\u5bb9:<\/p>\n<p>\u00a0\u00a0\u00a0 create table students<\/p>\n<p>\u00a0\u00a0\u00a0 \uff08<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id int unsigned not null auto_increment<br \/>\nprimary key,<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name char(8) not null,<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sex char(4) not null,<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 age tinyint unsigned not null,<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tel char(13) null default \u201c-\u201c<\/p>\n<p>\u00a0\u00a0\u00a0 );<\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u8f83\u957f\u7684\u8bed\u53e5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u53ef\u80fd\u5bb9\u6613\u8f93\u9519, \u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u5c06\u8bed\u53e5\u8f93\u5165\u597d\u540e\u4fdd\u5b58\u4e3a createtable.sql \u7684\u6587\u4ef6\u4e2d, \u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u7684\u6587\u4ef6\u91cd\u5b9a\u5411\u6267\u884c\u6267\u884c\u8be5\u811a\u672c\u3002<\/p>\n<p>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26, \u8f93\u5165:\u00a0<a href=\"https:\/\/www.raksmart.com\/cps\/7921\" target=\"_blank\" rel=\"noopener\">mysql<\/a> -D samp_db -u root -p &lt; createtable.sql<\/p>\n<p>(\u63d0\u793a: 1.\u5982\u679c\u8fde\u63a5\u8fdc\u7a0b\u4e3b\u673a\u8bf7\u52a0\u4e0a -h \u6307\u4ee4; 2.<br \/>\ncreatetable.sql \u6587\u4ef6\u82e5\u4e0d\u5728\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4e0b\u9700\u6307\u5b9a\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u3002)<\/p>\n<p>\u8bed\u53e5\u89e3\u8bf4:<\/p>\n<p>create table tablename(columns) \u4e3a\u521b\u5efa\u6570\u636e\u5e93\u8868\u7684\u547d\u4ee4, \u5217\u7684\u540d\u79f0\u4ee5\u53ca\u8be5\u5217\u7684\u6570\u636e\u7c7b\u578b\u5c06\u5728\u62ec\u53f7\u5185\u5b8c\u6210;<\/p>\n<p>\u62ec\u53f7\u5185\u58f0\u660e\u4e865\u5217\u5185\u5bb9, id\u3001name\u3001sex\u3001age\u3001tel\u4e3a\u6bcf\u5217\u7684\u540d\u79f0, \u540e\u9762\u8ddf\u7684\u662f\u6570\u636e\u7c7b\u578b\u63cf\u8ff0, \u5217\u4e0e\u5217\u7684\u63cf\u8ff0\u4e4b\u95f4\u7528\u9017\u53f7(,)\u9694\u5f00;<\/p>\n<p>\u4ee5 \u201cid int unsigned not null<br \/>\nauto_increment primary key\u201d \u884c\u8fdb\u884c\u4ecb\u7ecd:<\/p>\n<ul>\n<li>\u201cid\u201d \u4e3a\u5217\u7684\u540d\u79f0;<\/li>\n<li>\u201cint\u201d \u6307\u5b9a\u8be5\u5217\u7684\u7c7b\u578b\u4e3a int(\u53d6\u503c\u8303\u56f4\u4e3a -8388608\u52308388607), \u5728\u540e\u9762\u6211\u4eec\u53c8\u7528 \u201cunsigned\u201d \u52a0\u4ee5\u4fee\u9970, \u8868\u793a\u8be5\u7c7b\u578b\u4e3a\u65e0\u7b26\u53f7\u578b, \u6b64\u65f6\u8be5\u5217\u7684\u53d6\u503c\u8303\u56f4\u4e3a 0\u523016777215;<\/li>\n<li>\u201cnot null\u201d \u8bf4\u660e\u8be5\u5217\u7684\u503c\u4e0d\u80fd\u4e3a\u7a7a, \u5fc5\u987b\u8981\u586b, \u5982\u679c\u4e0d\u6307\u5b9a\u8be5\u5c5e\u6027, \u9ed8\u8ba4\u53ef\u4e3a\u7a7a;<\/li>\n<li>\u201cauto_increment\u201d \u9700\u5728\u6574\u6570\u5217\u4e2d\u4f7f\u7528, \u5176\u4f5c\u7528\u662f\u5728\u63d2\u5165\u6570\u636e\u65f6\u82e5\u8be5\u5217\u4e3a NULL, MySQL\u5c06\u81ea\u52a8\u4ea7\u751f\u4e00\u4e2a\u6bd4\u73b0\u5b58\u503c\u66f4\u5927\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u503c\u3002\u5728\u6bcf\u5f20\u8868\u4e2d\u4ec5\u80fd\u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u503c\u4e14\u6240\u5728\u5217\u5fc5\u987b\u4e3a\u7d22\u5f15\u5217\u3002<\/li>\n<li>\u201cprimary key\u201d \u8868\u793a\u8be5\u5217\u662f\u8868\u7684\u4e3b\u952e, \u672c\u5217\u7684\u503c\u5fc5\u987b\u552f\u4e00, MySQL\u5c06\u81ea\u52a8\u7d22\u5f15\u8be5\u5217\u3002<\/li>\n<li>\u4e0b\u9762\u7684 char(8) \u8868\u793a\u5b58\u50a8\u7684\u5b57\u7b26\u957f\u5ea6\u4e3a8, tinyint\u7684\u53d6\u503c\u8303\u56f4\u4e3a -127\u5230128, default \u5c5e\u6027\u6307\u5b9a\u5f53\u8be5\u5217\u503c\u4e3a\u7a7a\u65f6\u7684\u9ed8\u8ba4\u503c\u3002\u66f4\u591a\u7684\u76f8\u5173\u5185\u5bb9\u53ef\u4ee5\u9605\u8bfb<a href=\"https:\/\/cn.raksmart.com\/blog\/knowledge\/680.html\">MYSQL\u6559\u7a0b\uff081\uff09<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u7684\u5e16\u5b50\uff0c\u6211\u4eec\u5c06\u7ee7\u7eed\u56f4\u7ed5Mysql\u6570\u636e\u5e93\u5c55\u5f00\u5185\u5bb9\uff0c\u63a5\u4e0b\u6765\u4e00\u8d77\u548cRaksmart\u7f8e\u56fd\u670d\u52a1\u5668\u5c0f\u7f16\u6765\u770b\u770b\u2026 <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[1017],"class_list":["post-682","post","type-post","status-publish","format-standard","hentry","category-knowledge","tag-mysql"],"_links":{"self":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/comments?post=682"}],"version-history":[{"count":0,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts\/682\/revisions"}],"wp:attachment":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/media?parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/categories?post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/tags?post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}