{"id":6349,"date":"2024-07-18T19:49:56","date_gmt":"2024-07-18T11:49:56","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6349"},"modified":"2024-07-18T19:49:56","modified_gmt":"2024-07-18T11:49:56","slug":"mysql-%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98%e5%8f%8a%e8%a7%a3%e7%ad%94","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6349","title":{"rendered":"MySQL \u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u7b54"},"content":{"rendered":"<p>\u5728\u9762\u8bd5 MySQL \u76f8\u5173\u7684\u804c\u4f4d\u65f6\uff0c\u901a\u5e38\u4f1a\u6d89\u53ca\u4e00\u4e9b\u57fa\u7840\u548c\u9ad8\u7ea7\u7684\u6570\u636e\u5e93\u7ba1\u7406\u3001\u4f18\u5316\u3001\u8bbe\u8ba1\u7b49\u65b9\u9762\u7684\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684 MySQL \u9762\u8bd5\u95ee\u9898\u53ca\u5176\u89e3\u7b54\uff1a<\/p>\n<h3>\u57fa\u7840\u95ee\u9898<\/h3>\n<ol>\n<li>\n<p><strong>\u4ec0\u4e48\u662f MySQL\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1aMySQL \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff08RDBMS\uff09\uff0c\u4f7f\u7528\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff08SQL\uff09\u8fdb\u884c\u6570\u636e\u5e93\u7684\u521b\u5efa\u3001\u7ba1\u7406\u548c\u64cd\u4f5c\u3002\u5b83\u662f\u6700\u6d41\u884c\u7684\u6570\u636e\u5e93\u4e4b\u4e00\uff0c\u5e38\u7528\u4e8e Web \u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>MySQL \u652f\u6301\u54ea\u4e9b\u5b58\u50a8\u5f15\u64ce\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1aMySQL \u652f\u6301\u591a\u79cd\u5b58\u50a8\u5f15\u64ce\uff0c\u5305\u62ec InnoDB\u3001MyISAM\u3001Memory\u3001CSV\u3001Merge\u3001Archive \u7b49\u3002\u5176\u4e2d\uff0cInnoDB \u662f\u9ed8\u8ba4\u7684\u5b58\u50a8\u5f15\u64ce\uff0c\u652f\u6301\u4e8b\u52a1\u5904\u7406\u3001\u884c\u7ea7\u9501\u5b9a\u548c\u5916\u952e\u7ea6\u675f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>MySQL \u548c SQL \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1aMySQL \u662f\u4e00\u4e2a\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u800c SQL\uff08\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u64cd\u4f5c\u548c\u67e5\u8be2\u6570\u636e\u5e93\u7684\u7f16\u7a0b\u8bed\u8a00\u3002MySQL \u4f7f\u7528 SQL \u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u67e5\u8be2\u4e0e\u64cd\u4f5c<\/h3>\n<ol start=\"4\">\n<li>\n<p><strong>\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u548c\u8868\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<pre><code class=\"language-sql\">CREATE DATABASE example_db;\nUSE example_db;\nCREATE TABLE example_table (\nid INT AUTO_INCREMENT PRIMARY KEY,\nname VARCHAR(100),\nage INT\n);<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u67e5\u8be2\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u6570\u636e\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<pre><code class=\"language-sql\">SELECT * FROM example_table WHERE age > 25;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u66f4\u65b0\u8868\u4e2d\u7684\u6570\u636e\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<pre><code class=\"language-sql\">UPDATE example_table SET age = 30 WHERE name = 'John';<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<pre><code class=\"language-sql\">DELETE FROM example_table WHERE age < 20;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u4f18\u5316\u4e0e\u6027\u80fd<\/h3>\n<ol start=\"8\">\n<li>\n<p><strong>\u5982\u4f55\u4f18\u5316 MySQL \u67e5\u8be2\u6027\u80fd\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528\u5408\u9002\u7684\u7d22\u5f15\u3002<\/li>\n<li>\u907f\u514d\u5728 WHERE \u5b50\u53e5\u4e2d\u4f7f\u7528\u51fd\u6570\u3002<\/li>\n<li>\u4f7f\u7528 JOIN \u4ee3\u66ff\u5b50\u67e5\u8be2\u3002<\/li>\n<li>\u907f\u514d SELECT *\uff0c\u53ea\u9009\u62e9\u5fc5\u8981\u7684\u5217\u3002<\/li>\n<li>\u4f7f\u7528\u67e5\u8be2\u7f13\u5b58\uff08\u6839\u636e\u5177\u4f53\u60c5\u51b5\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u7d22\u5f15\uff1f\u5b83\u6709\u4ec0\u4e48\u4f5c\u7528\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u7d22\u5f15\u662f\u4e00\u79cd\u7528\u4e8e\u63d0\u9ad8\u6570\u636e\u5e93\u67e5\u8be2\u901f\u5ea6\u7684\u6570\u636e\u7ed3\u6784\u3002\u901a\u8fc7\u5728\u8868\u7684\u67d0\u4e00\u5217\u6216\u591a\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\uff0c\u53ef\u4ee5\u52a0\u5feb\u6570\u636e\u68c0\u7d22\u7684\u901f\u5ea6\uff0c\u4f46\u4f1a\u589e\u52a0\u5199\u64cd\u4f5c\u7684\u5f00\u9500\u548c\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u67e5\u770b\u4e00\u4e2a\u8868\u7684\u7d22\u5f15\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<pre><code class=\"language-sql\">SHOW INDEX FROM example_table;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u4e8b\u52a1\u4e0e\u9501<\/h3>\n<ol start=\"11\">\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u4e8b\u52a1\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u4e8b\u52a1\u662f\u4e00\u7ec4\u903b\u8f91\u64cd\u4f5c\u5355\u5143\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u8981\u4e48\u5168\u90e8\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u3002\u4e8b\u52a1\u5177\u6709 ACID \u7279\u6027\uff1a\u539f\u5b50\u6027\u3001\u4e00\u81f4\u6027\u3001\u9694\u79bb\u6027\u548c\u6301\u4e45\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u9501\uff1fMySQL \u652f\u6301\u54ea\u4e9b\u7c7b\u578b\u7684\u9501\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u9501\u662f\u4e3a\u4e86\u4fdd\u62a4\u6570\u636e\u5e93\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u800c\u91c7\u53d6\u7684\u4e00\u79cd\u673a\u5236\u3002MySQL \u652f\u6301\u884c\u7ea7\u9501\uff08InnoDB\uff09\u3001\u8868\u7ea7\u9501\uff08MyISAM\uff09\u548c\u9875\u9762\u7ea7\u9501\uff08Memory \u5f15\u64ce\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u9ad8\u7ea7\u95ee\u9898<\/h3>\n<ol start=\"13\">\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u8303\u5f0f\uff1f\u5e38\u89c1\u7684\u8303\u5f0f\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u8303\u5f0f\u662f\u6570\u636e\u5e93\u8bbe\u8ba1\u7684\u51c6\u5219\uff0c\u7528\u4e8e\u51cf\u5c11\u6570\u636e\u5197\u4f59\u548c\u63d0\u9ad8\u6570\u636e\u4e00\u81f4\u6027\u3002\u5e38\u89c1\u7684\u8303\u5f0f\u6709\u7b2c\u4e00\u8303\u5f0f\uff081NF\uff09\u3001\u7b2c\u4e8c\u8303\u5f0f\uff082NF\uff09\u3001\u7b2c\u4e09\u8303\u5f0f\uff083NF\uff09\u3001BCNF \u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u8fdb\u884c\u6570\u636e\u5e93\u7684\u5907\u4efd\u548c\u6062\u590d\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\n<pre><code class=\"language-bash\"># \u5907\u4efd\u6570\u636e\u5e93\nmysqldump -u username -p database_name > backup_file.sql\n# \u6062\u590d\u6570\u636e\u5e93\nmysql -u username -p database_name < backup_file.sql<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u5916\u952e\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u5916\u952e\u662f\u4e00\u79cd\u7ea6\u675f\uff0c\u7528\u4e8e\u786e\u4fdd\u4e00\u4e2a\u8868\u4e2d\u7684\u6570\u636e\u4e0e\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u6570\u636e\u4e4b\u95f4\u7684\u53c2\u7167\u5b8c\u6574\u6027\u3002\u5916\u952e\u53ef\u4ee5\u9632\u6b62\u5b64\u7acb\u8bb0\u5f55\uff0c\u5e76\u786e\u4fdd\u5f15\u7528\u7684\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u4f18\u5316 MySQL \u914d\u7f6e\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574 MySQL \u914d\u7f6e\u6587\u4ef6\uff08my.cnf \u6216 my.ini\uff09\u4e2d\u7684\u53c2\u6570\u6765\u4f18\u5316 MySQL \u6027\u80fd\uff0c\u4f8b\u5982 <code>innodb_buffer_pool_size<\/code>\u3001<code>query_cache_size<\/code>\u3001<code>max_connections<\/code> \u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u5206\u5e03\u5f0f\u4e0e\u96c6\u7fa4<\/h3>\n<ol start=\"17\">\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u4e3b\u4ece\u590d\u5236\uff1f\u5982\u4f55\u8bbe\u7f6e\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u4e3b\u4ece\u590d\u5236\u662f\u5c06\u6570\u636e\u4ece\u4e00\u4e2a MySQL \u670d\u52a1\u5668\uff08\u4e3b\u670d\u52a1\u5668\uff09\u590d\u5236\u5230\u4e00\u4e2a\u6216\u591a\u4e2a MySQL \u670d\u52a1\u5668\uff08\u4ece\u670d\u52a1\u5668\uff09\u7684\u8fc7\u7a0b\u3002\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u4e3b\u670d\u52a1\u5668\u7684 <code>binlog<\/code> \u548c\u4ece\u670d\u52a1\u5668\u7684 <code>relay log<\/code> \u6765\u5b9e\u73b0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ec0\u4e48\u662f\u5206\u533a\uff1f<\/strong><\/p>\n<ul>\n<li><strong>\u56de\u7b54<\/strong>\uff1a\u5206\u533a\u662f\u4e00\u79cd\u5c06\u8868\u7684\u6570\u636e\u5206\u5272\u6210\u591a\u4e2a\u90e8\u5206\u7684\u65b9\u6cd5\uff0c\u6bcf\u4e2a\u90e8\u5206\u79f0\u4e3a\u4e00\u4e2a\u5206\u533a\u3002\u5206\u533a\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u548c\u7ba1\u7406\u5927\u578b\u8868\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u719f\u6089\u548c\u638c\u63e1\u8fd9\u4e9b\u5e38\u89c1\u7684 MySQL \u95ee\u9898\u53ca\u5176\u89e3\u7b54\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728\u9762\u8bd5\u4e2d\u66f4\u597d\u5730\u5c55\u793a\u81ea\u5df1\u7684\u6570\u636e\u5e93\u77e5\u8bc6\u548c\u6280\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9762\u8bd5 MySQL \u76f8\u5173\u7684\u804c\u4f4d\u65f6\uff0c\u901a\u5e38\u4f1a\u6d89\u53ca\u4e00\u4e9b\u57fa\u7840\u548c\u9ad8\u7ea7\u7684\u6570\u636e\u5e93\u7ba1\u7406\u3001\u4f18\u5316\u3001\u8bbe\u8ba1\u7b49\u65b9\u9762\u7684\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6349\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[126],"class_list":["post-6349","post","type-post","status-publish","format-standard","hentry","category-123","tag-mysql"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6349"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6349\/revisions"}],"predecessor-version":[{"id":6350,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6349\/revisions\/6350"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}