{"id":682,"date":"2020-06-30T09:58:01","date_gmt":"2020-06-30T01:58:01","guid":{"rendered":"https:\/\/raksmart.cn\/blog\/?p=682"},"modified":"2020-06-30T09:58:03","modified_gmt":"2020-06-30T01:58:03","slug":"mysql%e6%95%99%e7%a8%8b%ef%bc%882%ef%bc%89","status":"publish","type":"post","link":"https:\/\/raksmart.cn\/blog\/knowledge\/682.html","title":{"rendered":"Mysql\u6559\u7a0b\uff082\uff09"},"content":{"rendered":"\n<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<strong><a href=\"https:\/\/raksmart.cn\/\" 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\n\n\n<p>\u521b\u5efa\u6570\u636e\u5e93\u8868<\/p>\n\n\n\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\n\n\n<p>create table \u8868\u540d\u79f0(\u5217\u58f0\u660e);<\/p>\n\n\n\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\n\n\n<p>&nbsp;&nbsp;&nbsp; create table students<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; \uff08<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id int unsigned not null auto_increment\nprimary key,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name char(8) not null,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sex char(4) not null,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; age tinyint unsigned not null,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tel char(13) null default &#8220;-&#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; );<\/p>\n\n\n\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\n\n\n<p>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26, \u8f93\u5165:&nbsp;mysql -D samp_db -u root -p &lt; createtable.sql<\/p>\n\n\n\n<p>(\u63d0\u793a: 1.\u5982\u679c\u8fde\u63a5\u8fdc\u7a0b\u4e3b\u673a\u8bf7\u52a0\u4e0a -h \u6307\u4ee4; 2.\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\n\n\n<p>\u8bed\u53e5\u89e3\u8bf4:<\/p>\n\n\n\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\n\n\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\n\n\n<p>\u4ee5 &#8220;id int unsigned not null\nauto_increment primary key&#8221; \u884c\u8fdb\u884c\u4ecb\u7ecd:<\/p>\n\n\n\n<ul><li>&#8220;id&#8221; \u4e3a\u5217\u7684\u540d\u79f0;<\/li><li>&#8220;int&#8221; \u6307\u5b9a\u8be5\u5217\u7684\u7c7b\u578b\u4e3a int(\u53d6\u503c\u8303\u56f4\u4e3a -8388608\u52308388607), \u5728\u540e\u9762\u6211\u4eec\u53c8\u7528 &#8220;unsigned&#8221; \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><li>&#8220;not null&#8221; \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><li>&#8220;auto_increment&#8221; \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><li>&#8220;primary key&#8221; \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><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:\/\/raksmart.cn\/blog\/knowledge\/680.html\">MYSQL\u6559\u7a0b\uff081\uff09<\/a><\/li><\/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&hellip; <a href=\"https:\/\/raksmart.cn\/blog\/knowledge\/682.html\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">Mysql\u6559\u7a0b\uff082\uff09<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[107],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/posts\/682"}],"collection":[{"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/comments?post=682"}],"version-history":[{"count":1,"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/posts\/682\/revisions"}],"predecessor-version":[{"id":683,"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/posts\/682\/revisions\/683"}],"wp:attachment":[{"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/media?parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/categories?post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raksmart.cn\/blog\/wp-json\/wp\/v2\/tags?post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}