{"id":2032,"date":"2020-07-29T23:18:21","date_gmt":"2020-07-29T15:18:21","guid":{"rendered":"http:\/\/39.97.231.10\/?p=2032"},"modified":"2020-07-29T23:18:21","modified_gmt":"2020-07-29T15:18:21","slug":"mysql%e6%97%a5%e5%b8%b8%e4%bd%bf%e7%94%a8%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=2032","title":{"rendered":"MySQL\u65e5\u5e38\u4f7f\u7528\u7684\u57fa\u672c\u547d\u4ee4"},"content":{"rendered":"<div>\n<h2>\u5b89\u88c5\u90e8\u7f72MySQL\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528MySQL\u4e86\u3002MySQL\u65e5\u5e38\u4f7f\u7528\u4e3b\u8981\u5305\u62ec\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u521b\u5efa\u6570\u636e\u5e93\uff0c\u521b\u5efa\u8868\uff0c\u63d2\u5165\u6570\u636e\uff0c\u4fee\u6539\u6570\u636e\uff0c\u5220\u9664\u6570\u636e\uff0c\u67e5\u8be2\u6570\u636e\u7b49\u7b49\uff0c\u4e0b\u9762\u5c06\u4ecb\u7ecdMySQL\u6700\u57fa\u672c\u7684\u65e5\u5e38\u4f7f\u7528\u547d\u4ee4\u3002<\/h2>\n<\/div>\n<div>\n<div>\n<h5>\u4e00\u3001\u8fde\u63a5MySQL<\/h5>\n<p>\u901a\u5e38\u4f7f\u7528mysql\u5ba2\u6237\u7aef\u547d\u4ee4\u8fde\u63a5\u5230MySQL\u670d\u52a1\u5668\uff0c\u5982\u4e0b\uff1a<br \/>\nmysql -h 127.0.0.1 -P 3306 -u admin -p\\&#8217;password\\&#8217; -A<br \/>\n\u5e38\u7528\u53c2\u6570\uff1a<br \/>\n-h\uff1a\u6307\u5b9aMySQL\u670d\u52a1\u5668IP<br \/>\n-P\uff1a\u6307\u5b9aMySQL\u7aef\u53e3\u53f7<br \/>\n-u\uff1a\u6307\u5b9a\u7528\u6237\u540d<br \/>\n-p\uff1a\u6307\u5b9a\u5bc6\u7801<br \/>\n-A\uff1a\u4e0d\u81ea\u52a8\u91cd\u5efaHASH\u503c\uff0c\u5728\u8868\u6570\u91cf\u7279\u522b\u591a\u7684\u573a\u666f\u4e0b\uff0c\u6b64\u53c2\u6570\u80fd\u52a0\u5feb\u8fde\u63a5\u3002<\/p>\n<h5>\u4e8c\u3001\u521b\u5efa\u3001\u5220\u9664\u6570\u636e\u5e93<\/h5>\n<p>\u4e00\u4e2aMySQL\u5b9e\u4f8b\u53ef\u4ee5\u521b\u5efa\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u4e5f\u79f0\u4e4b\u4e3aschema\uff0c\u521b\u5efa\u6570\u636e\u5e93\u8bed\u6cd5\u5982\u4e0b\uff1a<br \/>\ncreate database db1;<br \/>\n\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u8bed\u6cd5\uff0c\u4e24\u8005\u7b49\u540c\uff1a<br \/>\ncreate schema db2;<br \/>\n\u5982\u679c\u4e00\u4e2a\u6570\u636e\u5e93\u5df2\u7ecf\u5b58\u5728\uff0c\u521b\u5efa\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u6570\u636e\u5e93\u65f6\u4f1a\u62a5\u9519\uff0c\u53ef\u4ee5\u4f7f\u7528if not exists\u8bed\u6cd5\uff0c\u53ea\u6709\u5728\u6570\u636e\u5e93\u4e0d\u5b58\u5728\u65f6\u624d\u521b\u5efa\u3002\u5982\u4e0b\uff1a<br \/>\ncreate database if not exists db1;<br \/>\n\u67e5\u770b\u5f53\u524dMySQL\u5b9e\u4f8b\u4e2d\u6709\u591a\u5c11\u4e2a\u6570\u636e\u5e93\uff08schema\uff09:<br \/>\nshow databases;<br \/>\n\u5220\u9664\u6570\u636e\u5e93\uff1a<br \/>\ndrop database db1;<br \/>\n\u6216\u8005<br \/>\ndrop schema db2;<br \/>\n\u5982\u679c\u5220\u9664\u7684\u6570\u636e\u5e93\u5df2\u7ecf\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u5220\u9664\u64cd\u4f5c\u4f1a\u62a5\u9519\uff0c\u53ef\u4ee5\u4f7f\u7528if exists\u8bed\u6cd5\uff0c\u53ea\u6709\u5728\u6570\u636e\u5e93\u5b58\u5728\u7684\u6761\u4ef6\u4e0b\u624d\u4f1a\u5220\u9664\u3002\u5982\u4e0b\uff1a<br \/>\ndrop database if exists db1;<\/p>\n<h5>\u4e09\u3001\u521b\u5efa\u3001\u5220\u9664\u8868<\/h5>\n<p>\u8868\u662f\u6570\u636e\u5e93\u7684\u6838\u5fc3\uff0c\u901a\u5e38\u4e00\u4e2a\u8868\u5305\u62ec\u5b57\u6bb5\u3001\u4e3b\u952e\u3001\u7d22\u5f15\u7b49\u7b49\uff0c\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u793a\u4f8b\uff0c\u770b\u770b\u5982\u4f55\u521b\u5efaMySQL\u8868\u3002<\/p>\n<pre>CREATE TABLE tb (\n\u00a0 id int(11) NOT NULL AUTO_INCREMENT,\n\u00a0 name varchar(50) DEFAULT NULL,\n\u00a0 age int(11) NOT NULL,\n\u00a0 PRIMARY KEY (id),\n\u00a0 KEY idx_name(name)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8\n<\/pre>\n<p>\u4e0a\u8ff0\u5efa\u8868\u8bed\u53e5\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u8868tb\uff0c\u5305\u542bid,name,age\u4e09\u4e2a\u5b57\u6bb5\u3002id\u5b57\u6bb5\u4e3aint\u578b\uff0c\u81ea\u589e\u5217\uff0c\u4e3b\u952e\uff0cname\u5b57\u6bb5\u4e3avarchar(50)\uff0c\u8be5\u5b57\u6bb5\u4e0a\u6709\u4e00\u4e2a\u4e8c\u7ea7\u7d22\u5f15\uff0cengine=innodb\u8868\u660e\u8be5\u8868\u7684\u5b58\u50a8\u5f15\u64ce\u662finnodb\uff0cinnodb\u4e5f\u662f\u9ed8\u8ba4\u7684\u5b58\u50a8\u5f15\u64ce\uff0c\u4e5f\u662f\u4f7f\u7528\u6700\u591a\u7684\u4e00\u79cdMySQL\u5b58\u50a8\u5f15\u64ce\u3002\u9ed8\u8ba4\u5b57\u7b26\u96c6\u662futf8\u3002<br \/>\n\u5220\u9664\u8868\uff1a<br \/>\ndrop table tb;<br \/>\n\u521b\u5efa\u8868\u548c\u5220\u9664\u8868\u4e5f\u53ef\u4ee5\u4f7f\u7528if exists\u8bed\u6cd5\u3002\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>create table if not exists tb(id int auto_increment, name varchar(50), age int not null, primary key(id), key idx_name(name));<\/li>\n<li>drop table if exists tb;<\/li>\n<\/ul>\n<h5>\u56db\u3001\u5bf9\u8868\u8fdb\u884c\u589e\u5220\u6539\u67e5<\/h5>\n<p>\u67e5\u8be2\u8bb0\u5f55\uff1a<br \/>\nselect name,age from tb;<br \/>\n\u63d2\u5165\u8bb0\u5f55\uff1a<br \/>\ninsert into tb(name,age) values(\\&#8217;Tom\\&#8217;, 10);<br \/>\n\u4fee\u6539\u8bb0\u5f55\uff1a<br \/>\nupdate tb set age = age+1 where name=\\&#8217;Tom\\&#8217;;<br \/>\n\u5220\u9664\u8bb0\u5f55\uff1a<br \/>\ndelete from tb where name=\\&#8217;Tom\\&#8217;;<br \/>\n\u6e05\u7a7a\u8868\u4e2d\u6240\u6709\u8bb0\u5f55\uff1a<br \/>\ntruncate table tb;\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5\u90e8\u7f72MySQL\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528MySQL\u4e86\u3002MySQL\u65e5\u5e38\u4f7f\u7528\u4e3b\u8981\u5305\u62ec\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u521b\u5efa\u6570\u636e\u5e93\uff0c\u521b\u5efa\u8868\uff0c\u63d2\u5165 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=2032\"> <span class=\"screen-reader-text\">MySQL\u65e5\u5e38\u4f7f\u7528\u7684\u57fa\u672c\u547d\u4ee4<\/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":"\u5b89\u88c5\u90e8\u7f72MySQL\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528MySQL\u4e86\u3002MySQL\u65e5\u5e38\u4f7f\u7528\u4e3b\u8981\u5305\u62ec\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u521b\u5efa\u6570\u636e\u5e93\uff0c\u521b\u5efa\u8868\uff0c\u63d2\u5165&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2032"}],"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=2032"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2032\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2032"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}