{"id":745,"date":"2023-02-02T11:31:35","date_gmt":"2023-02-02T03:31:35","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=745"},"modified":"2024-07-08T12:44:35","modified_gmt":"2024-07-08T04:44:35","slug":"mysql-%e5%b8%b8%e7%94%a8%e8%af%ad%e6%b3%95%e5%92%8c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%ef%bc%882%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2023\/02\/02\/mysql-%e5%b8%b8%e7%94%a8%e8%af%ad%e6%b3%95%e5%92%8c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%ef%bc%882%ef%bc%89\/","title":{"rendered":"MySQL \u5e38\u7528\u8bed\u6cd5\u548c\u6570\u636e\u7c7b\u578b\uff082\uff09"},"content":{"rendered":"<p>\u9605\u8bfbMySQL\u8bed\u6cd5\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7684\u89c4\u5219\uff1a<\/p>\n<p>\u2460\u7b26\u53f7\u7528\u6765\u6307\u51fa\u51e0\u4e2a\u9009\u62e9\u4e2d\u7684\u4e00\u4e2a\uff0c\u6bd4\u5982\uff1anull | not null\u8868\u793a\u6216\u8005\u7ed9\u51fanull\u6216\u8005\u7ed9\u51fanot null\uff1b<\/p>\n<p>\u2461\u5305\u542b\u5728\u65b9\u62ec\u53f7\u4e2d\u7684\u5173\u952e\u5b57\u6216\u5b50\u53e5\uff08\u5982[like this]\uff09\u662f\u53ef\u9009\u7684\uff1b<\/p>\n<p>\u2462\u65e2\u6ca1\u6709\u5217\u51fa\u6240\u6709\u7684MySQL\u8bed\u53e5\uff0c\u4e5f\u6ca1\u6709\u5217\u51fa\u6bcf\u4e00\u6761\u5b50\u53e5\u548c\u9009\u9879\u3002<\/p>\n<p>\u4e00\u3001\u5e38\u7528\u8bed\u6cd5<\/p>\n<p>1\u3001alter table\uff1a\u66f4\u65b0\u5df2\u5b58\u5728\u8868\u7684\u6a21\u5f0f<\/p>\n<p>alter table tablename<\/p>\n<p>( \u00a0 \u00a0 \u00a0add column datatype [null | not null] [constarints],<\/p>\n<p>change column columns datatype [null | not null] \u00a0[contarints].<\/p>\n<p>drop column,);<\/p>\n<p>2\u3001commit\uff1a\u5c06\u4e8b\u52a1\u5904\u7406\u5199\u5230\u6570\u636e\u5e93<\/p>\n<p>commit\uff1b<\/p>\n<p>3\u3001create index\uff1a\u5728\u4e00\u4e2a\u6216\u591a\u4e2a\u5217\u4e0a\u521b\u5efa\u7d22\u5f15<\/p>\n<p>create index indexname\u00a0on tablename (column \u00a0[asc | desc],&#8230;);<\/p>\n<p>4\u3001create procedure\uff1a\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b<\/p>\n<p>create procedure procedurename( [parameters] ) \u00a0begin &#8230;&#8230;\u00a0end;<\/p>\n<p>5\u3001create table\uff1a\u521b\u5efa\u65b0\u6570\u636e\u5e93\u8868<\/p>\n<p>create table tablename<\/p>\n<p>( \u00a0 \u00a0 \u00a0 \u00a0\u00a0column datatype [null | not null] [constraints],<\/p>\n<p>column datatype [null | not null] [constraints],<\/p>\n<p>&#8230;&#8230;);<\/p>\n<p>6\u3001create user\uff1a\u5411\u7cfb\u7edf\u4e2d\u6dfb\u52a0\u65b0\u7684\u7528\u6237\u8d26\u6237<\/p>\n<p>create user username[@hostname]<\/p>\n<p>[identified by [passwrod] &#8216;password&#8217;];<\/p>\n<p>7\u3001create view\uff1a\u521b\u5efa\u4e00\u4e2a\u6216\u591a\u4e2a\u8868\u4e0a\u7684\u65b0\u89c6\u56fe<\/p>\n<p>create [or replace] view viewname\u00a0as\u00a0select &#8230;;<\/p>\n<p>8\u3001delete\uff1a\u4ece\u8868\u4e2d\u5220\u9664\u4e00\u884c\u6216\u591a\u884c<\/p>\n<p>delete from tablename [where &#8230;];<\/p>\n<p>9\u3001drop\uff1a\u6c38\u4e45\u5220\u9664\u6570\u636e\u5e93\u5bf9\u8c61\uff08\u8868\u3001\u89c6\u56fe\u3001\u7d22\u5f15\u7b49\uff09<\/p>\n<p>drop database | index | procedure | table | trigger | user | view itemname;<\/p>\n<p>10\u3001insert\uff1a\u7ed9\u8868\u589e\u52a0\u4e00\u884c<\/p>\n<p>insert into tablename [(columns,&#8230;)] values(values,&#8230;)<\/p>\n<p>11\u3001insert select\uff1a\u63d2\u5165select\u7ed3\u679c\u5230\u4e00\u4e2a\u8868<\/p>\n<p>insert into tablename[(columns,&#8230;)]<\/p>\n<p>select columns,&#8230; from tablename,&#8230;<\/p>\n<p>[where &#8230;];<\/p>\n<p>12\u3001rollback\uff1a\u64a4\u9500\u4e00\u4e2a\u4e8b\u52a1\u5904\u7406\u5757<\/p>\n<p>rollback [ to saveprointname];<\/p>\n<p>13\u3001savepoint\uff1a\u4e3a\u4f7f\u7528rollback\u8bed\u53e5\u8bbe\u7acb\u4fdd\u7559\u70b9<\/p>\n<p>savepoint sql;<\/p>\n<p>14\u3001select\uff1a\u4ece\u4e00\u4e2a\u6216\u591a\u4e2a\u8868\uff08\u89c6\u56fe\uff09\u4e2d\u68c0\u7d22\u6570\u636e<\/p>\n<p>select columnname,&#8230; from tablename,&#8230;<\/p>\n<p>[where &#8230;]<\/p>\n<p>[union &#8230;]<\/p>\n<p>[group by &#8230;]<\/p>\n<p>[having &#8230;]<\/p>\n<p>[order by &#8230;]<\/p>\n<p>15\u3001start transaction\uff1a\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\u5904\u7406\u5757\u7684\u5f00\u59cb<\/p>\n<p>start transaction;<\/p>\n<p>16\u3001update\uff1a\u66f4\u65b0\u8868\u4e2d\u7684\u4e00\u884c\u6216\u591a\u884c<\/p>\n<p>uptable tablename set columname = value, &#8230; [where &#8230;];<\/p>\n<p>\u4e8c\u3001\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u6570\u636e\u7c7b\u578b\uff1a\u5b9a\u4e49\u5217\u4e2d\u53ef\u4ee5\u5b58\u50a8\u4ec0\u4e48\u6570\u636e\u4ee5\u53ca\u8be5\u6570\u636e\u5b9e\u9645\u600e\u6837\u5b58\u50a8\u7684\u57fa\u672c\u89c4\u5219\uff0c\u5176\u7528\u4e8e\u4ee5\u4e0b\u51e0\u4e2a\u76ee\u7684\uff1a<\/p>\n<p>\u2460\u5141\u8bb8\u9650\u5236\u53ef\u5b58\u50a8\u5728\u5217\u4e2d\u7684\u6570\u636e<\/p>\n<p>\u2461\u5141\u8bb8\u5728\u5185\u90e8\u66f4\u6709\u6548\u7684\u5b58\u50a8\u6570\u636e<\/p>\n<p>\u2462\u5141\u8bb8\u53d8\u6362\u6392\u5e8f\u987a\u5e8f\uff08\u4f5c\u4e3a\u6570\u503c\u6570\u636e\u7c7b\u578b\uff0c\u6570\u503c\u624d\u80fd\u6b63\u786e\u6392\u5e8f\uff09<\/p>\n<p>1\u3001\u4e32\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u8be5\u7c7b\u578b\u4e3a\u6700\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b\uff0c\u7528\u6765\u5b58\u50a8\u4e32\uff08\u6bd4\u5982\u540d\u5b57\u3001\u5730\u5740\u7b49\uff09\uff1b\u6709\u4e24\u79cd\u4e32\u7c7b\u578b\uff0c\u5206\u522b\u662f\u5b9a\u957f\u4e32\u548c\u53d8\u957f\u4e32<\/p>\n<p>\u5b9a\u957f\u4e32\uff1a\u63a5\u53d7\u957f\u5ea6\u56fa\u5b9a\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u957f\u5ea6\u5b9e\u5728\u521b\u5efa\u8868\u65f6\u6307\u5b9a\u7684\uff1b\u5b9a\u957f\u5217\u4e0d\u5141\u8bb8\u591a\u4f59\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u76ee\uff0c\u5b83\u4eec\u5206\u914d\u7684\u5b58\u50a8\u7a7a\u95f4\u4e0e\u6307\u5b9a\u7684\u4e00\u6837\u591a\uff08\u6bd4\u5982char\uff09<\/p>\n<p>\u53d8\u957f\u4e32\uff1a\u5b58\u50a8\u53ef\u53d8\u957f\u5ea6\u7684\u6587\u672c\uff0c\u6709\u4e9b\u53d8\u957f\u6570\u636e\u7c7b\u578b\u5177\u6709\u6700\u5927\u5b9a\u957f\uff0c\u6709\u4e9b\u662f\u5b8c\u5168\u53d8\u957f\u7684\uff0c\u4e0d\u8bba\u54ea\u79cd\uff0c\u6307\u5b9a\u7684\u6570\u636e\u5f97\u5230\u4fdd\u5b58\u5373\u53ef\uff08\u7075\u6d3b\uff09<\/p>\n<p>PS:MySQL\u5904\u7406\u5b9a\u957f\u5217\u6bd4\u53d8\u957f\u5217\u5feb\u901f\u7684\u5f88\u591a\uff0c\u4e14MySQL\u4e0d\u8bb8\u4e91\u5bf9\u53d8\u957f\u5217\uff08\u6216\u4e00\u4e2a\u5217\u7684\u53ef\u53d8\u90e8\u5206\uff09\u8fdb\u884c\u7d22\u5f15<\/p>\n<p>\u4e32\u6570\u636e\u7c7b\u578b\u8868\uff1a<\/p>\n<figure class=\"\">\n<div class=\"image-block\">\n<div class=\"\"><img decoding=\"async\" src=\"http:\/\/blog.nonot.cn\/wp-content\/uploads\/2023\/02\/20230202113210-bc681.png\" \/><\/div>\n<\/div>\n<\/figure>\n<p>PS\uff1a\u2460\u4e0d\u7ba1\u662f\u7528\u4efb\u4f55\u5f62\u5f0f\u7684\u4e32\u6570\u636e\u7c7b\u578b\uff0c\u4e32\u503c\u90fd\u5fc5\u987b\u62ec\u5728\u5f15\u53f7\u5185\uff08\u901a\u5e38\u4f7f\u7528\u5355\u5f15\u53f7\uff09<\/p>\n<p>\u2461\u5982\u679c\u6570\u503c\u662f\u8ba1\u7b97\uff08\u6c42\u548c\u5e73\u5747\u7b49\uff09\u4e2d\u4f7f\u7528\u7684\u6570\u503c\uff0c\u5e94\u5b58\u50a8\u5728\u6570\u503c\u6570\u636e\u7c7b\u578b\u5217\u4e2d\uff1b\u5982\u679c\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff08\u53ef\u80fd\u53ea\u5305\u542b\u6570\u5b57\uff09\u4f7f\u7528\uff0c\u5219\u5e94\u4fdd\u5b58\u5728\u4e32\u6570\u636e\u7c7b\u578b\u5217\u4e2d\uff1b<\/p>\n<p>2\u3001\u6570\u503c\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u6570\u503c\u6570\u636e\u7c7b\u578b\u5b58\u50a8\u6570\u503c\uff0cMySQL\u652f\u6301\u591a\u79cd\u6570\u503c\u6570\u636e\u7c7b\u578b\uff0c\u6bcf\u79cd\u5b58\u50a8\u7684\u6570\u503c\u5177\u6709\u4e0d\u540c\u7684\u53d6\u503c\u8303\u56f4\uff1b<\/p>\n<p>\u6570\u503c\u6570\u636e\u7c7b\u578b\u8868\uff1a<\/p>\n<figure class=\"\">\n<div class=\"image-block\">\n<div class=\"\"><img decoding=\"async\" src=\"http:\/\/blog.nonot.cn\/wp-content\/uploads\/2023\/02\/20230202113210-7bde4.png\" \/><\/div>\n<\/div>\n<\/figure>\n<p>PS\uff1a\u6240\u6709\u6570\u503c\u6570\u636e\u7c7b\u578b\uff08\u9664bit\u548cbollean\uff09\u90fd\u53ef\u4ee5\u6709\u7b26\u53f7\u6216\u8005\u65e0\u7b26\u53f7\uff0c\u6709\u7b26\u53f7\u6570\u503c\u5217\u53ef\u4ee5\u5b58\u50a8\u6b63\u6216\u8d1f\u7684\u6570\u503c\uff0c\u65e0\u7b26\u53f7\u6570\u503c\u5217\u53ea\u80fd\u5b58\u50a8\u6b63\u6570\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e3a\u6709\u7b26\u53f7\uff08\u4e0e\u4e32\u4e0d\u540c\uff0c\u6570\u503c\u4e0d\u5e94\u8be5\u5728\u62ec\u53f7\u5185\uff09<\/p>\n<p>3\u3001\u65e5\u671f\u548c\u65f6\u95f4\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u65e5\u671f\u548c\u65f6\u95f4\u6570\u636e\u7c7b\u578b\u8868\uff1a<\/p>\n<figure class=\"\">\n<div class=\"image-block\">\n<div class=\"\"><img decoding=\"async\" src=\"http:\/\/blog.nonot.cn\/wp-content\/uploads\/2023\/02\/20230202113211-b686c.png\" \/><\/div>\n<\/div>\n<\/figure>\n<p>4\u3001\u4e8c\u8fdb\u5236\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u4e8c\u8fdb\u5236\u6570\u636e\u7c7b\u578b\u53ef\u5b58\u50a8\u4efb\u4f55\u6570\u636e\uff08\u751a\u81f3\u5305\u62ec\u4e8c\u8fdb\u5236\u4fe1\u606f\uff09\uff0c\u5982\u56fe\u50cf\u3001\u591a\u5a92\u4f53\u3001\u5b57\u5904\u7406\u6587\u6863\u7b49<\/p>\n<p>\u4e8c\u8fdb\u5236\u6570\u636e\u7c7b\u578b\u8868\uff1a<\/p>\n<figure class=\"\">\n<div class=\"image-block\">\n<div class=\"\"><img decoding=\"async\" src=\"http:\/\/blog.nonot.cn\/wp-content\/uploads\/2023\/02\/20230202113211-1c3ce.png\" \/><\/div>\n<\/div>\n<\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u9605\u8bfbMySQL\u8bed\u6cd5\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7684\u89c4\u5219\uff1a \u2460\u7b26\u53f7\u7528\u6765\u6307\u51fa\u51e0\u4e2a\u9009&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-745","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=745"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/745\/revisions"}],"predecessor-version":[{"id":1133,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/745\/revisions\/1133"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}