{"id":2004,"date":"2020-07-29T23:05:51","date_gmt":"2020-07-29T15:05:51","guid":{"rendered":"http:\/\/39.97.231.10\/?p=2004"},"modified":"2020-07-29T23:05:51","modified_gmt":"2020-07-29T15:05:51","slug":"mysql%e4%bf%ae%e6%94%b9%e8%a1%a8%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=2004","title":{"rendered":"MySQL\u4fee\u6539\u8868\u7ed3\u6784"},"content":{"rendered":"<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div>\nMySQL\u4f7f\u7528alter table\u8bed\u6cd5\u5bf9\u8868\u7ed3\u6784\u8fdb\u884c\u4fee\u6539\uff0c\u6bd4\u5982\u6dfb\u52a0\u5b57\u6bb5\uff0c\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b\uff0c\u5220\u9664\u5b57\u6bb5\uff0c\u6dfb\u52a0\u7d22\u5f15\uff0c\u5220\u9664\u7d22\u5f15\uff0c\u4fee\u6539\u5b57\u7b26\u96c6\u7b49\u7b49\uff0c\u4e0b\u9762\u603b\u7ed3\u4e86\u4e00\u4e9b\u5e38\u7528\u7684\u4fee\u6539\u8868\u7ed3\u6784\u793a\u4f8b\u3002<\/p>\n<h5>\u4e00\u3001\u4fee\u6539\u5b57\u6bb5<\/h5>\n<p><strong>1\u3001\u589e\u52a0\u5b57\u6bb5<\/strong><br \/>\nalter table tb add column age int default 0 comment \\&#8217;age\\&#8217;;<br \/>\n<strong>2\u3001\u5728\u67d0\u4e2a\u5b57\u6bb5\u4e4b\u540e\u589e\u52a0\u5b57\u6bb5<\/strong><br \/>\nalter table tb add column name varchar(50) default null comment \\&#8217;name\\&#8217; after id;<br \/>\n<strong>3\u3001\u589e\u52a0\u5b57\u6bb5\uff0c\u653e\u5728\u8868\u5b57\u6bb5\u7684\u5f00\u5934<\/strong><br \/>\nalter table tb add column type varchar(50) default null comment \\&#8217;type\\&#8217; first;<br \/>\n<strong>4\u3001\u5220\u9664\u5b57\u6bb5<\/strong><br \/>\nalter table tb drop column type;<br \/>\n<strong>5\u3001\u4fee\u6539\u5b57\u6bb5\u540d\u79f0\u6216\u8005\u7c7b\u578b<\/strong><br \/>\nalter table tb change age age_new int default 10 comment \\&#8217;age_new\\&#8217;;<br \/>\n<strong>6\u3001\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b<\/strong><br \/>\nalter table tb modify age varchar(50);<br \/>\nchange \u4e0e modify\u533a\u522b\u5728\u4e8echange\u53ef\u4ee5\u4fee\u6539\u5b57\u6bb5\u540d\u79f0\uff0c\u4e5f\u53ef\u4ee5\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b\uff0c\u800cmodify\u53ea\u80fd\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b\uff0c\u4e0d\u80fd\u4fee\u6539\u540d\u79f0\u3002<\/p>\n<h5>\u4e8c\u3001\u4fee\u6539\u7d22\u5f15<\/h5>\n<p><strong>1\u3001\u589e\u52a0\u5355\u5217\u7d22\u5f15<\/strong><br \/>\nalter table tb add index idx_name(name);<br \/>\n<strong>2\u3001\u589e\u52a0\u8054\u5408\u7d22\u5f15<\/strong><br \/>\nalter table tb add index idx_name_age(name,age);<br \/>\n<strong>3\u3001\u589e\u52a0\u552f\u4e00\u7d22\u5f15<\/strong><br \/>\nalter table tb add unique key uk_name(name);<br \/>\n<strong>4\u3001\u589e\u52a0\u4e3b\u952e<\/strong><br \/>\nalter table tb add primary key(id);<br \/>\n<strong>5\u3001\u5220\u9664\u4e3b\u952e<\/strong><br \/>\nalter table tb drop primary key;<br \/>\n<strong>6\u3001\u5220\u9664\u7d22\u5f15<\/strong><br \/>\nalter table tb drop index idx_name;<br \/>\n<strong>7\u3001\u4fee\u6539\u7d22\u5f15\u540d\u79f0<\/strong><br \/>\nalter table tb rename index idx_name_age to idx_name_age_new;<\/p>\n<h5>\u4e09\u3001\u4fee\u6539\u5b57\u7b26\u96c6<\/h5>\n<p><strong>1\u3001\u4fee\u6539\u6570\u636e\u5e93\u5b57\u7b26\u96c6<\/strong><br \/>\nalter database db_new charset utf8mb4;<br \/>\n<strong>2\u3001\u4fee\u6539\u8868\u5b57\u7b26\u96c6<\/strong><br \/>\nalter table tb charset=utf8mb4;<br \/>\n<strong>3\u3001\u4fee\u6539\u8868\u5b57\u7b26\u96c6\u548c\u6821\u9a8c\u89c4\u5219<\/strong><br \/>\nalter table tb charset=utf8mb4 collate=utf8mb4_general_ci;<br \/>\n<strong>4\u3001\u4fee\u6539\u8868\u5b57\u6bb5\u7684\u5b57\u7b26\u96c6\u548c\u6821\u9a8c\u89c4\u5219<\/strong><br \/>\nalter table tb modify name varchar(50) character set utf8 collate utf8_general_ci;<br \/>\n<strong>\u6ce8\u610f\uff1a<\/strong><br \/>\n\u5bf9\u540c\u4e00\u4e2a\u8868\u7684\u591a\u5904\u8868\u7ed3\u6784\u8fdb\u884c\u4fee\u6539\uff0c\u53ef\u653e\u5230\u4e00\u4e2aSQL\u91cc\u6267\u884c\uff0c\u907f\u514d\u5728\u8868\u6570\u636e\u91cf\u975e\u5e38\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u591a\u6b21\u6267\u884c\u6539\u8868SQL\uff0c\u8017\u65f6\u957f\uff0c\u5f71\u54cd\u6b63\u5e38\u6570\u636e\u5e93\u670d\u52a1\u3002<br \/>\n\u6bd4\u5982\uff1a\u589e\u52a0\u4e24\u4e2a\u5b57\u6bb5<br \/>\nalter table tb add column c1 int;<br \/>\nalter table tb add column c2 int;<br \/>\n\u5408\u5e76\u6210\u4e00\u4e2aSQL\uff1a<br \/>\nalter table tb add column c1 int, add column c2 int;\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u4f7f\u7528alter table\u8bed\u6cd5\u5bf9\u8868\u7ed3\u6784\u8fdb\u884c\u4fee\u6539\uff0c\u6bd4\u5982\u6dfb\u52a0\u5b57\u6bb5\uff0c\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b\uff0c\u5220\u9664\u5b57\u6bb5\uff0c\u6dfb\u52a0\u7d22\u5f15\uff0c\u5220\u9664 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=2004\"> <span class=\"screen-reader-text\">MySQL\u4fee\u6539\u8868\u7ed3\u6784<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL\u4f7f\u7528alter table\u8bed\u6cd5\u5bf9\u8868\u7ed3\u6784\u8fdb\u884c\u4fee\u6539\uff0c\u6bd4\u5982\u6dfb\u52a0\u5b57\u6bb5\uff0c\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b\uff0c\u5220\u9664\u5b57\u6bb5\uff0c\u6dfb\u52a0\u7d22\u5f15\uff0c\u5220\u9664&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2004"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2004"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2004\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2004"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}