{"id":35828,"date":"2025-05-06T17:17:26","date_gmt":"2025-05-06T09:17:26","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35828.html"},"modified":"2025-05-06T17:17:26","modified_gmt":"2025-05-06T09:17:26","slug":"%e6%85%a2sql%e5%a4%84%e7%90%86%e6%b5%81%e7%a8%8b%e5%92%8c%e5%b8%b8%e8%a7%81%e6%a1%88%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35828.html","title":{"rendered":"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b"},"content":{"rendered":"<p>\u00a0\u601d\u7ef4\u5bfc\u56fe:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"672\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091725-6819d3a51c646.png\" width=\"1000\" \/><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0 \u5728 MySQL \u6570\u636e\u5e93\u7ba1\u7406\u4e2d&#xff0c;\u6162\u67e5\u8be2\u662f\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u7684\u5e38\u89c1\u75db\u70b9\u3002\u968f\u7740 MySQL 8 \u7248\u672c\u7684\u666e\u53ca&#xff0c;\u5176\u65b0\u589e\u7279\u6027&#xff08;\u5982 CTE\u3001\u9690\u85cf\u7d22\u5f15\u3001JSON \u683c\u5f0f\u6267\u884c\u8ba1\u5212\u7b49&#xff09;\u4e3a\u6162\u67e5\u8be2\u4f18\u5316\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u5de5\u5177\u3002\u672c\u6587\u7ed3\u5408 MySQL 8 \u7684\u7279\u6027&#xff0c;\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u8be6\u89e3\u6162\u67e5\u8be2\u7684\u5b9a\u4f4d\u3001\u5206\u6790\u4e0e\u4f18\u5316\u5168\u6d41\u7a0b&#xff0c;\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<h2>\u4e00\u3001\u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7&#xff1a;\u7cbe\u51c6\u6355\u83b7\u6027\u80fd\u74f6\u9888<\/h2>\n<\/p>\n<h4>1. \u914d\u7f6e\u6587\u4ef6\u6c38\u4e45\u5f00\u542f&#xff08;\u63a8\u8350\u751f\u4ea7\u73af\u5883&#xff09;<\/h4>\n<\/p>\n<p>\u4fee\u6539 MySQL 8 \u7684\u914d\u7f6e\u6587\u4ef6my.cnf&#xff08;Linux&#xff09;\u6216my.ini&#xff08;Windows&#xff09;&#xff0c;\u6dfb\u52a0\u4ee5\u4e0b\u6838\u5fc3\u914d\u7f6e&#xff1a;\u4fee\u6539\u540e\u9700\u91cd\u542f MySQL \u670d\u52a1\u4f7f\u914d\u7f6e\u751f\u6548\u3002<\/p>\n<p>[mysqld]<br \/>\nslow_query_log &#061; 1                # \u542f\u7528\u6162\u67e5\u8be2\u65e5\u5fd7&#xff08;8.0&#043;\u9ed8\u8ba4\u5173\u95ed&#xff09;<br \/>\nslow_query_log_file &#061; \/var\/log\/mysql\/mysql-slow.log  # \u65e5\u5fd7\u6587\u4ef6\u8def\u5f84<br \/>\nlong_query_time &#061; 1.0             # \u6162\u67e5\u8be2\u9608\u503c&#xff08;\u8d85\u8fc71\u79d2\u8bb0\u5f55&#xff0c;\u5efa\u8bae\u6839\u636e\u4e1a\u52a1\u8c03\u6574&#xff09;<br \/>\nlog_queries_not_using_indexes &#061; 1 # \u8bb0\u5f55\u672a\u4f7f\u7528\u7d22\u5f15\u7684\u67e5\u8be2&#xff08;\u5173\u952e\u4f18\u5316\u7ebf\u7d22&#xff09;<br \/>\nlog_slow_admin_statements &#061; 1     # \u8bb0\u5f55\u6162\u7ba1\u7406\u8bed\u53e5&#xff08;\u5982ALTER TABLE&#xff0c;8.0\u65b0\u589e&#xff09; <\/p>\n<p>\u914d\u7f6e\u5b8c\u6bd5\u4e4b\u540e&#xff0c;\u901a\u8fc7\u4ee5\u4e0b\u6307\u4ee4\u91cd\u65b0\u542f\u52a8MySQL\u670d\u52a1\u5668\u8fdb\u884c\u6d4b\u8bd5&#xff0c;\u67e5\u770b\u6162\u65e5\u5fd7\u6587\u4ef6\u4e2d\u8bb0\u5f55\u7684\u4fe1\u606f\/var\/lib\/mysql\/localhost-slow.log\u3002\u5982\u56fe\u6240\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"190\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091725-6819d3a5497af.png\" width=\"1279\" \/><\/p>\n<\/p>\n<p>\u00a0<\/p>\n<h4>2. \u52a8\u6001\u914d\u7f6e&#xff08;\u4e34\u65f6\u8c03\u8bd5&#xff0c;\u65e0\u9700\u91cd\u542f&#xff09;<\/h4>\n<\/p>\n<p>\u901a\u8fc7 SQL \u547d\u4ee4\u5b9e\u65f6\u5f00\u542f\u6162\u65e5\u5fd7&#xff08;\u9700SUPER\u6743\u9650&#xff09;&#xff1a;<\/p>\n<p>SET GLOBAL slow_query_log &#061; ON;<br \/>\nSET GLOBAL long_query_time &#061; 1;  &#8212; \u9608\u503c\u8bbe\u4e3a1\u79d2<br \/>\nSET GLOBAL log_queries_not_using_indexes &#061; ON; <\/p>\n<h4>3. \u65e5\u5fd7\u5206\u6790&#xff1a;\u6838\u5fc3\u6307\u6807\u4e0e\u5de5\u5177<\/h4>\n<p>\u5173\u952e\u6307\u6807\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>Query_time&#xff1a;\u67e5\u8be2\u6267\u884c\u65f6\u95f4&#xff08;\u7cbe\u786e\u5230\u5fae\u79d2&#xff09;&#xff0c;\u76f4\u63a5\u53cd\u6620\u6162\u67e5\u8be2\u4e25\u91cd\u7a0b\u5ea6\u3002<\/li>\n<li>Rows_examined&#xff1a;\u626b\u63cf\u7684\u884c\u6570&#xff0c;\u82e5\u8fdc\u5927\u4e8eRows_sent&#xff08;\u8fd4\u56de\u884c\u6570&#xff09;&#xff0c;\u8bf4\u660e\u5b58\u5728\u5927\u91cf\u65e0\u6548\u626b\u63cf\u3002<\/li>\n<li>Full_scan&#xff1a;\u6807\u8bb0\u662f\u5426\u5168\u8868\u626b\u63cf&#xff08;Yes\u8868\u793a\u672a\u4f7f\u7528\u7d22\u5f15&#xff09;\u3002<\/li>\n<\/ul>\n<\/p>\n<p>\u5206\u6790\u5de5\u5177&#xff1a; \u539f\u751f\u5de5\u5177&#xff1a;\u4f7f\u7528mysqldumpslow\u8fc7\u6ee4\u65e5\u5fd7&#xff08;\u8bed\u6cd5\u4e0e 5.5 \u517c\u5bb9&#xff09;&#xff1a; \u00a0<\/p>\n<p># \u6309\u8017\u65f6\u6392\u5e8f&#xff0c;\u83b7\u53d6\u6700\u6162\u76845\u6761\u67e5\u8be2<br \/>\nmysqldumpslow -s t -t 5 \/var\/log\/mysql\/mysql-slow.log <\/p>\n<p># \u6309\u626b\u63cf\u884c\u6570\u6392\u5e8f&#xff0c;\u5b9a\u4f4d\u626b\u63cf\u884c\u6570\u6700\u591a\u7684\u67e5\u8be2<br \/>\nmysqldumpslow -s r -t 5 \/var\/log\/mysql\/mysql-slow.log<\/p>\n<p>\u53ef\u89c6\u5316\u5de5\u5177&#xff1a;\u63a8\u8350\u4f7f\u7528pt-query-digest&#xff08;Percona Toolkit \u7ec4\u4ef6&#xff09;&#xff0c;\u751f\u6210\u5305\u542b\u6267\u884c\u9891\u7387\u3001\u5e73\u5747\u8017\u65f6\u3001\u7d22\u5f15\u4f7f\u7528\u60c5\u51b5\u7684\u8be6\u7ec6\u62a5\u544a&#xff1a;<\/p>\n<p>pt-query-digest \/var\/log\/mysql\/mysql-slow.log &gt; slow_query_analysis.txt <\/p>\n<p>\u793a\u4f8b\u65e5\u5fd7\u7247\u6bb5&#xff1a;<\/p>\n<p># Time: 2025-05-05T15:00:00&#043;08:00<br \/>\n# User&#064;Host: app_user[app_user] &#064; 192.168.1.100 []<br \/>\n# Query_time: 2.865912  Lock_time: 0.000045  Rows_sent: 20  Rows_examined: 500000<br \/>\n# EXPLAIN for: SELECT * FROM orders WHERE status &#061; &#039;processing&#039; LIMIT 20; <\/p>\n<p>\u00a0\u95ee\u9898&#xff1a;\u626b\u63cf 50 \u4e07\u884c\u4ec5\u8fd4\u56de 20 \u884c&#xff0c;status\u5b57\u6bb5\u672a\u4f7f\u7528\u7d22\u5f15&#xff0c;\u89e6\u53d1\u5168\u8868\u626b\u63cf\u3002<\/p>\n<\/p>\n<h3>\u4e8c\u3001\u7528 EXPLAIN ANALYZE \u6df1\u5ea6\u5206\u6790\u6267\u884c\u8ba1\u5212&#xff08;MySQL 8 \u589e\u5f3a\u7279\u6027&#xff09;<\/h3>\n<p>MySQL 8 \u5f15\u5165<span style=\"color:#be191c\">EXPLAIN ANALYZE<\/span>\u547d\u4ee4&#xff0c;\u53ef\u83b7\u53d6\u66f4\u7cbe\u786e\u7684\u6267\u884c\u7edf\u8ba1\u4fe1\u606f&#xff08;\u9700\u5f00\u542f<span style=\"color:#be191c\">optimizer_switch<\/span>\u4e2d\u7684<span style=\"color:#be191c\">derived_merge&#061;off<\/span>\u4ee5\u907f\u514d\u4f18\u5316\u5668\u5408\u5e76\u5b50\u67e5\u8be2&#xff09;\u3002\u6838\u5fc3\u5173\u6ce8\u5b57\u6bb5&#xff1a;<\/p>\n<\/p>\n<h4>1.\u00a0type&#xff08;\u8fde\u63a5\u7c7b\u578b&#xff0c;\u6548\u7387\u4f18\u5148\u7ea7&#xff09;<\/h4>\n<table>\n<tr>\u7c7b\u578b\u8bf4\u660e\u4f18\u5316\u76ee\u6807<\/tr>\n<tbody>\n<tr>\n<td>system<\/td>\n<td style=\"width:257px\">\u5355\u8868\u4e14\u4ec5\u6709\u4e00\u884c\u6570\u636e&#xff08;\u7279\u6b8aconst&#xff09;<\/td>\n<td style=\"width:349px\">\u7406\u60f3\u72b6\u6001&#xff0c;\u65e0\u9700\u4f18\u5316<\/td>\n<\/tr>\n<tr>\n<td>const<\/td>\n<td style=\"width:257px\">\u4e3b\u952e \/ \u552f\u4e00\u7d22\u5f15\u7cbe\u51c6\u5339\u914d<\/td>\n<td style=\"width:349px\">\u4f18\u5148\u901a\u8fc7\u4e3b\u952e \/ \u552f\u4e00\u7d22\u5f15\u67e5\u8be2<\/td>\n<\/tr>\n<tr>\n<td>range<\/td>\n<td style=\"width:257px\">\u7d22\u5f15\u8303\u56f4\u67e5\u8be2&#xff08;\u5982BETWEEN\/IN&#xff09;<\/td>\n<td style=\"width:349px\">\u5408\u7406\u4f7f\u7528\u7d22\u5f15&#xff0c;\u65e0\u9700\u5f3a\u5236\u4f18\u5316<\/td>\n<\/tr>\n<tr>\n<td>ALL<\/td>\n<td style=\"width:257px\">\u5168\u8868\u626b\u63cf&#xff08;\u5fc5\u987b\u4f18\u5316&#xff01;&#xff09;<\/td>\n<td style=\"width:349px\">\u6dfb\u52a0\u7d22\u5f15\u6216\u6539\u5199\u67e5\u8be2\u6761\u4ef6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. key\u4e0ekey_len<\/h4>\n<ul>\n<li>key&#061;NULL&#xff1a;\u672a\u4f7f\u7528\u7d22\u5f15&#xff0c;\u9700\u68c0\u67e5WHERE\u6761\u4ef6\u662f\u5426\u89e6\u53d1\u7d22\u5f15\u5931\u6548\u3002<\/li>\n<li>key_len&#xff1a;\u7d22\u5f15\u4f7f\u7528\u7684\u5b57\u8282\u957f\u5ea6&#xff0c;\u53cd\u6620\u662f\u5426\u5b8c\u5168\u4f7f\u7528\u8054\u5408\u7d22\u5f15&#xff08;\u5982(user_id, order_date)\u7684key_len&#061;8\u8868\u793a\u4ec5\u4f7f\u7528user_id\u5217&#xff09;\u3002<\/li>\n<\/ul>\n<h4>3. Extra&#xff08;\u5173\u952e\u4f18\u5316\u4fe1\u53f7&#xff09;<\/h4>\n<ul>\n<li>Using filesort&#xff1a;\u6587\u4ef6\u6392\u5e8f&#xff08;\u9700\u901a\u8fc7\u7d22\u5f15\u8986\u76d6ORDER BY\u5b57\u6bb5&#xff09;\u3002<\/li>\n<li>Using temporary&#xff1a;\u4e34\u65f6\u8868&#xff08;\u5206\u7ec4 \/ \u6392\u5e8f\u65f6\u4ea7\u751f&#xff0c;\u5c3d\u91cf\u901a\u8fc7\u7d22\u5f15\u907f\u514d&#xff09;\u3002<\/li>\n<li>Using index&#xff1a;\u8986\u76d6\u7d22\u5f15&#xff08;\u7406\u60f3\u72b6\u6001&#xff0c;\u65e0\u9700\u56de\u8868&#xff09;\u3002<\/li>\n<\/ul>\n<p> \u6848\u4f8b&#xff1a;<\/p>\n<p>\u5168\u8868\u626b\u63cf\u4f18\u5316&#xff08;MySQL 8 \u4e13\u5c5e JSON \u683c\u5f0f\u8f93\u51fa&#xff09;\u539f\u67e5\u8be2&#xff08;\u672a\u52a0\u7d22\u5f15&#xff09;&#xff1a;\u00a0<\/p>\n<p>EXPLAIN ANALYZE SELECT * FROM users WHERE email &#061; &#039;user&#064;example.com&#039;; <\/p>\n<p>JSON \u6267\u884c\u8ba1\u5212\u7247\u6bb5&#xff08;\u7b80\u5316\u540e&#xff09;&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;query_block&#034;: {<br \/>\n    &#034;table&#034;: {<br \/>\n      &#034;table_name&#034;: &#034;users&#034;,<br \/>\n      &#034;access_type&#034;: &#034;ALL&#034;,  &#8212; \u5168\u8868\u626b\u63cf<br \/>\n      &#034;rows_examined_per_scan&#034;: 100000  &#8212; \u626b\u63cf10\u4e07\u884c<br \/>\n    }<br \/>\n  }<br \/>\n} <\/p>\n<p>\u4f18\u5316\u540e&#xff08;\u6dfb\u52a0\u7d22\u5f15\u5e76\u4f7f\u7528\u8986\u76d6\u7d22\u5f15&#xff09;&#xff1a;<\/p>\n<p>ALTER TABLE users ADD INDEX idx_email_cover (email, name, phone);  &#8212; \u8986\u76d6\u7d22\u5f15<br \/>\nEXPLAIN ANALYZE SELECT name, phone FROM users WHERE email &#061; &#039;user&#064;example.com&#039;; <\/p>\n<p>\u6267\u884c\u8ba1\u5212&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;query_block&#034;: {<br \/>\n    &#034;table&#034;: {<br \/>\n      &#034;table_name&#034;: &#034;users&#034;,<br \/>\n      &#034;access_type&#034;: &#034;ref&#034;,  &#8212; \u7d22\u5f15\u5f15\u7528<br \/>\n      &#034;rows_examined_per_scan&#034;: 1,<br \/>\n      &#034;using_index&#034;: true  &#8212; \u8986\u76d6\u7d22\u5f15&#xff0c;\u65e0\u9700\u56de\u8868<br \/>\n    }<br \/>\n  }<br \/>\n} <\/p>\n<p>\u6548\u679c&#xff1a;\u626b\u63cf\u884c\u6570\u4ece 10 \u4e07\u964d\u81f3 1&#xff0c;\u67e5\u8be2\u65f6\u95f4\u4ece 2.5 \u79d2\u7f29\u77ed\u81f3 0.01 \u79d2\u3002<\/p>\n<\/p>\n<h3>\u4e09\u3001\u7d22\u5f15\u4f18\u5316&#xff1a;MySQL 8 \u7684\u65b0\u7279\u6027\u4e0e\u7ecf\u5178\u89c4\u5219<\/h3>\n<h5><\/h5>\n<h4>1. \u907f\u5f00\u7d22\u5f15\u5931\u6548\u7684 5 \u5927 \u201c\u9677\u9631\u201d<\/h4>\n<\/p>\n<p>\u9677\u9631 1&#xff1a;Like<font face=\"monospace\">&#039;%\u524d\u7f00&#039;<\/font>\u5bfc\u81f4\u7d22\u5f15\u5931\u6548<\/p>\n<p>\u9519\u8bef\u5199\u6cd5&#xff08;\u5168\u8868\u626b\u63cf&#xff09;&#xff1a;<\/p>\n<p>SELECT * FROM products WHERE name LIKE &#039;%\u7b14\u8bb0\u672c&#039;;  &#8212; \u4ee5%\u5f00\u5934&#xff0c;\u7d22\u5f15\u5931\u6548 <\/p>\n<p>\u4f18\u5316&#xff08;\u524d\u7f00\u5339\u914d&#xff0c;\u7d22\u5f15\u6709\u6548&#xff09;&#xff1a;<\/p>\n<p>SELECT * FROM products WHERE name LIKE &#039;\u7b14\u8bb0\u672c%&#039;;  &#8212; \u5339\u914d\u201c\u7b14\u8bb0\u672c\u201d\u5f00\u5934\u7684\u5b57\u7b26\u4e32 <\/p>\n<h5>\u9677\u9631 2&#xff1a;OR\u6761\u4ef6\u6df7\u5408\u65e0\u7d22\u5f15\u5217<\/h5>\n<p>\u9519\u8bef\u5199\u6cd5&#xff08;\u7d22\u5f15\u5931\u6548&#xff09;&#xff1a;<\/p>\n<p>SELECT * FROM orders WHERE user_id &#061; 100 OR address LIKE &#039;%\u4e0a\u6d77&#039;;  &#8212; user_id\u6709\u7d22\u5f15&#xff0c;address\u65e0\u7d22\u5f15 <\/p>\n<p>\u4f18\u5316\u65b9\u6848&#xff1a;<\/p>\n<ul>\n<li>\u4e3aaddress\u6dfb\u52a0\u7d22\u5f15&#xff08;\u9002\u5408\u9ad8\u9891\u67e5\u8be2&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p>ALTER TABLE orders ADD INDEX idx_address (address(20));  &#8212; \u524d\u7f00\u7d22\u5f15&#xff08;MySQL 8\u652f\u6301&#xff09; <\/p>\n<ul>\n<li>\u6539\u7528UNION ALL&#xff08;\u51cf\u5c11\u4e34\u65f6\u8868\u5f00\u9500&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p>SELECT * FROM orders WHERE user_id &#061; 100<br \/>\nUNION ALL<br \/>\nSELECT * FROM orders WHERE address LIKE &#039;%\u4e0a\u6d77&#039;; <\/p>\n<h5>\u9677\u9631 3&#xff1a;\u591a\u5217\u7d22\u5f15\u672a\u9075\u5faa \u201c\u6700\u5de6\u5339\u914d\u201d<\/h5>\n<p>\u7d22\u5f15\u5b9a\u4e49&#xff1a;ALTER TABLE sales ADD INDEX idx_date_prod (order_date, product_id); \u6709\u6548\u67e5\u8be2&#xff08;\u4f7f\u7528\u7d22\u5f15&#xff09;&#xff1a;<\/p>\n<p>&#8212; \u4ec5\u7528\u7b2c\u4e00\u5217&#xff08;\u8303\u56f4\u67e5\u8be2&#xff09;<br \/>\nSELECT * FROM sales WHERE order_date &gt; &#039;2025-01-01&#039;;<br \/>\n&#8212; \u7528\u524d\u4e24\u5217&#xff08;\u7cbe\u51c6\u5339\u914d&#xff09;<br \/>\nSELECT * FROM sales WHERE order_date &#061; &#039;2025-01-01&#039; AND product_id &#061; 101; <\/p>\n<p>\u65e0\u6548\u67e5\u8be2&#xff08;\u8df3\u8fc7\u7b2c\u4e00\u5217&#xff0c;\u7d22\u5f15\u5931\u6548&#xff09;&#xff1a;<\/p>\n<p>SELECT * FROM sales WHERE product_id &#061; 101;  &#8212; \u4ec5\u7528\u7b2c\u4e8c\u5217&#xff0c;\u4e0d\u4f7f\u7528\u7d22\u5f15 <\/p>\n<h4>2. MySQL 8 \u4e13\u5c5e\u4f18\u5316\u6280\u5de7<\/h4>\n<h5><\/h5>\n<h5>&#xff08;1&#xff09;\u9690\u85cf\u7d22\u5f15&#xff08;\u6d4b\u8bd5\u7d22\u5f15\u6709\u6548\u6027&#xff09;<\/h5>\n<p>\u901a\u8fc7INVISIBLE\u5173\u952e\u5b57\u4e34\u65f6\u9690\u85cf\u7d22\u5f15&#xff0c;\u6d4b\u8bd5\u5176\u5bf9\u67e5\u8be2\u7684\u5f71\u54cd&#xff1a;<\/p>\n<p>ALTER TABLE users ALTER INDEX idx_email INVISIBLE;  &#8212; \u9690\u85cf\u7d22\u5f15<br \/>\nEXPLAIN SELECT * FROM users WHERE email &#061; &#039;test&#064;example.com&#039;;  &#8212; \u89c2\u5bdf\u662f\u5426\u8d70\u5168\u8868\u626b\u63cf<br \/>\nALTER TABLE users ALTER INDEX idx_email VISIBLE;  &#8212; \u6062\u590d\u7d22\u5f15 <\/p>\n<h5>&#xff08;2&#xff09;\u964d\u5e8f\u7d22\u5f15&#xff08;\u4f18\u5316\u5012\u5e8f\u6392\u5e8f&#xff09;<\/h5>\n<p>MySQL 8 \u652f\u6301\u964d\u5e8f\u7d22\u5f15&#xff0c;\u907f\u514dDESC\u6392\u5e8f\u65f6\u7684\u6587\u4ef6\u6392\u5e8f&#xff1a;<\/p>\n<p>ALTER TABLE orders ADD INDEX idx_order_date_desc (order_date DESC);<br \/>\n&#8212; \u4f18\u5316\u540e\u65e0\u9700\u6587\u4ef6\u6392\u5e8f<br \/>\nSELECT * FROM orders ORDER BY order_date DESC LIMIT 10; <\/p>\n<h3>\u56db\u3001\u6570\u636e\u5e93\u7ed3\u6784\u4f18\u5316&#xff1a;\u4ece\u8bbe\u8ba1\u5c42\u51cf\u5c11\u67e5\u8be2\u538b\u529b<\/h3>\n<h4>1. \u62c6\u5206\u5927\u8868&#xff1a;\u5206\u79bb\u9ad8\u9891\u4e0e\u4f4e\u9891\u5b57\u6bb5<\/h4>\n<p>\u573a\u666f&#xff1a;user_info\u8868\u5305\u542b 30 \u4e2a\u5b57\u6bb5&#xff0c;\u5176\u4e2dresume&#xff08;\u7b80\u5386&#xff09;\u548ccertificate&#xff08;\u8bc1\u4e66&#xff09;\u5b57\u6bb5\u6781\u5c11\u4f7f\u7528&#xff0c;\u5bfc\u81f4\u5168\u8868\u626b\u63cf\u7f13\u6162\u3002<\/p>\n<\/p>\n<p>\u4f18\u5316\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u521b\u5efa\u9ad8\u9891\u5b57\u6bb5\u8868user_basic&#xff08;\u5b58\u653e\u5e38\u7528\u5b57\u6bb5&#xff09;&#xff1a;<\/li>\n<p>CREATE TABLE user_basic (<br \/>\n    id BIGINT PRIMARY KEY AUTO_INCREMENT,<br \/>\n    username VARCHAR(50) NOT NULL,<br \/>\n    email VARCHAR(100) UNIQUE,<br \/>\n    created_at DATETIME DEFAULT CURRENT_TIMESTAMP<br \/>\n); <\/p>\n<p>\u00a0<\/p>\n<p>\u00a0 \u00a0 2.\u521b\u5efa\u4f4e\u9891\u5b57\u6bb5\u8868user_extend&#xff08;\u901a\u8fc7\u5916\u952e\u5173\u8054&#xff09;&#xff1a;<\/p>\n<p>CREATE TABLE user_extend (<br \/>\n    id BIGINT PRIMARY KEY,<br \/>\n    resume TEXT,<br \/>\n    certificate JSON,  &#8212; MySQL 8\u652f\u6301\u539f\u751fJSON\u7c7b\u578b<br \/>\n    FOREIGN KEY (id) REFERENCES user_basic(id)<br \/>\n); <\/p>\n<p>\u6548\u679c&#xff1a;\u9ad8\u9891\u67e5\u8be2&#xff08;\u5982\u767b\u5f55\u3001\u7528\u6237\u5217\u8868&#xff09;\u4ec5\u8bbf\u95eeuser_basic&#xff0c;\u626b\u63cf\u884c\u6570\u51cf\u5c11 60%\u3002<\/p>\n<\/p>\n<h4>2. \u4e2d\u95f4\u8868\u4f18\u5316\u590d\u6742\u5173\u8054\u67e5\u8be2<\/h4>\n<p>\u573a\u666f&#xff1a;\u9891\u7e41\u7edf\u8ba1 \u201c\u7528\u6237\u8fd1 30 \u5929\u8ba2\u5355\u91d1\u989d\u201d&#xff0c;\u9700\u5173\u8054users\u3001orders\u3001order_items\u4e09\u5f20\u8868&#xff0c;\u6267\u884c\u65f6\u95f4\u8d85\u8fc7 3 \u79d2\u3002<\/p>\n<p> \u4f18\u5316\u65b9\u6848&#xff1a;\u521b\u5efa\u7edf\u8ba1\u4e2d\u95f4\u8868user_order_stats&#xff0c;\u6bcf\u65e5\u5b9a\u65f6\u540c\u6b65\u6570\u636e&#xff1a;<\/p>\n<\/p>\n<p>CREATE TABLE user_order_stats (<br \/>\n    user_id BIGINT PRIMARY KEY,<br \/>\n    total_amount DECIMAL(10, 2),<br \/>\n    order_count INT,<br \/>\n    last_update DATE,<br \/>\n    INDEX idx_last_update (last_update)  &#8212; \u6309\u65f6\u95f4\u67e5\u8be2\u7d22\u5f15<br \/>\n);<\/p>\n<p>&#8212; \u66ff\u4ee3\u590d\u6742\u5173\u8054\u67e5\u8be2&#xff08;\u539f\u97003\u8868JOIN&#xff09;<br \/>\nSELECT total_amount FROM user_order_stats WHERE user_id &#061; 123 AND last_update &#061; CURDATE(); <\/p>\n<p>\u6548\u679c&#xff1a;\u67e5\u8be2\u65f6\u95f4\u4ece 3 \u79d2\u964d\u81f3 0.1 \u79d2&#xff0c;\u6d88\u9664\u591a\u8868 JOIN \u5f00\u9500\u3002<\/p>\n<\/p>\n<h3>\u4e94\u3001\u5b9e\u6218\u6280\u5de7&#xff1a;\u5904\u7406\u9ad8\u9891\u6162\u67e5\u8be2\u573a\u666f<\/h3>\n<h4>1. \u6df1\u5ea6\u5206\u9875\u4f18\u5316&#xff08;LIMIT offset, size\u6027\u80fd\u95ee\u9898&#xff09;<\/h4>\n<p>\u95ee\u9898&#xff1a;LIMIT 100000, 20\u9700\u626b\u63cf 100020 \u884c&#xff0c;\u4e22\u5f03\u524d 100000 \u884c&#xff0c;\u6548\u7387\u6781\u4f4e\u3002<\/p>\n<\/p>\n<p>MySQL 8 \u4f18\u5316\u65b9\u6848&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u65b9\u6848 1&#xff1a;\u5229\u7528\u8986\u76d6\u7d22\u5f15\u51cf\u5c11\u56de\u8868<\/li>\n<\/ul>\n<p>&#8212; \u5148\u83b7\u53d6\u4e3b\u952e&#xff08;\u51cf\u5c11\u626b\u63cf\u5b57\u6bb5&#xff09;<br \/>\nSELECT id FROM orders ORDER BY create_time LIMIT 100000, 20;<br \/>\n&#8212; \u518d\u901a\u8fc7\u4e3b\u952e\u6279\u91cf\u67e5\u8be2&#xff08;IN\u64cd\u4f5c\u6bd4\u5b50\u67e5\u8be2\u9ad8\u6548&#xff09;<br \/>\nSELECT * FROM orders WHERE id IN (100001, 100002, &#8230;, 100020); <\/p>\n<ul>\n<li>\u65b9\u6848 2&#xff1a;\u8bb0\u5f55\u4e0a\u6b21\u5206\u9875 ID&#xff08;\u6eda\u52a8\u5206\u9875&#xff09;<\/li>\n<\/ul>\n<p>&#8212; \u57fa\u4e8e\u4e0a\u6b21\u6700\u5927ID\u5206\u9875&#xff0c;\u907f\u514d\u504f\u79fb\u91cf\u7d2f\u79ef<br \/>\nSELECT * FROM orders WHERE id &gt; 100000 ORDER BY id LIMIT 20; <\/p>\n<p>\u00a0<\/p>\n<h4>2. \u5206\u89e3\u5173\u8054\u67e5\u8be2&#xff1a;\u5e94\u7528\u5c42\u7ec4\u88c5\u7ed3\u679c&#xff08;\u9002\u5408\u9ad8\u5e76\u53d1&#xff09;<\/h4>\n<\/p>\n<p>\u539f\u590d\u6742\u67e5\u8be2&#xff08;3 \u8868 JOIN&#xff0c;\u6267\u884c\u65f6\u95f4 2 \u79d2&#xff09;&#xff1a;<\/p>\n<p>SELECT u.username, o.order_id, p.product_name<br \/>\nFROM users u<br \/>\nJOIN orders o ON u.id &#061; o.user_id<br \/>\nJOIN products p ON o.product_id &#061; p.id<br \/>\nWHERE u.country &#061; &#039;China&#039; AND o.status &#061; &#039;paid&#039;; <\/p>\n<p>\u4f18\u5316\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u67e5\u8be2\u7528\u6237 ID \u5217\u8868&#xff1a;<\/li>\n<p>SELECT id, username FROM users WHERE country &#061; &#039;China&#039;;  &#8212; \u5355\u8868\u67e5\u8be2&#xff0c;0.05\u79d2 <\/p>\n<p>\u00a0 \u00a0 \u00a02. \u67e5\u8be2\u8ba2\u5355 ID \u4e0e\u4ea7\u54c1 ID&#xff1a;<\/p>\n<p>SELECT order_id, product_id FROM orders WHERE user_id IN (1,2,3) AND status &#061; &#039;paid&#039;;  &#8212; 0.1\u79d2 <\/p>\n<p>\u00a0 \u00a0 3.\u67e5\u8be2\u4ea7\u54c1\u540d\u79f0&#xff1a;<\/p>\n<p>SELECT product_id, product_name FROM products WHERE product_id IN (101, 102);  &#8212; 0.03\u79d2 <\/p>\n<p>\u603b\u8017\u65f6\u964d\u81f3 0.18 \u79d2&#xff0c;\u76f8\u6bd4\u539f\u67e5\u8be2\u63d0\u5347 10 \u500d\u4ee5\u4e0a\u3002<\/p>\n<\/p>\n<h3>\u516d\u3001MySQL 8 \u65b0\u589e\u7279\u6027\u52a9\u529b\u4f18\u5316<\/h3>\n<h4>1. CTE&#xff08;\u516c\u5171\u8868\u8868\u8fbe\u5f0f&#xff09;\u7b80\u5316\u590d\u6742\u5b50\u67e5\u8be2<\/h4>\n<\/p>\n<p>&#8212; \u539f\u5d4c\u5957\u5b50\u67e5\u8be2&#xff08;\u53ef\u8bfb\u6027\u5dee&#xff0c;\u6613\u89e6\u53d1\u5168\u8868\u626b\u63cf&#xff09;<br \/>\nSELECT * FROM orders WHERE user_id IN (SELECT id FROM users WHERE score &gt; 80);<\/p>\n<p>&#8212; \u6539\u7528CTE&#xff08;\u6e05\u6670\u4e14\u4fbf\u4e8e\u4f18\u5316\u5668\u5206\u6790&#xff09;<br \/>\nWITH high_score_users AS (<br \/>\n    SELECT id FROM users WHERE score &gt; 80<br \/>\n)<br \/>\nSELECT * FROM orders WHERE user_id IN (SELECT id FROM high_score_users); <\/p>\n<\/p>\n<h4>2. \u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f\u81ea\u52a8\u66f4\u65b0&#xff08;8.0.17&#043;&#xff09;<\/h4>\n<p>\u901a\u8fc7AUTO_RECALCULATE\u53c2\u6570\u81ea\u52a8\u66f4\u65b0\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f&#xff0c;\u907f\u514d\u56e0\u7edf\u8ba1\u4fe1\u606f\u9648\u65e7\u5bfc\u81f4\u7684\u6267\u884c\u8ba1\u5212\u504f\u5dee&#xff1a;<\/p>\n<p>ALTER TABLE users ALTER INDEX idx_email AUTO_RECALCULATE DEFAULT ON; <\/p>\n<h3>\u4e03\u3001\u6700\u4f73\u5b9e\u8df5&#xff1a;\u5efa\u7acb\u6162\u67e5\u8be2\u4f18\u5316\u95ed\u73af<\/h3>\n<li>\n<p>\u5b9a\u671f\u5ba1\u8ba1\u6d41\u7a0b&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u65e5\u901a\u8fc7<span style=\"color:#be191c\">SHOW GLOBAL STATUS LIKE &#039;Slow_queries&#039;<\/span>\u76d1\u63a7\u6162\u67e5\u8be2\u6570\u91cf\u3002<\/li>\n<li>\u6bcf\u5468\u7528<span style=\"color:#be191c\">pt-query-digest<\/span>\u751f\u6210\u62a5\u544a&#xff0c;\u91cd\u70b9\u4f18\u5316Rows_examined &gt; 5\u4e07\u6216Query_time &gt; 1\u79d2\u7684\u8bed\u53e5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7d22\u5f15\u8bbe\u8ba1\u4e09\u539f\u5219&#xff1a;<\/p>\n<ul>\n<li>\u4e3a\u9ad8\u9891\u67e5\u8be2\u7684<span style=\"color:#be191c\">WHERE\/ORDER BY\/GROUP BY<\/span>\u5b57\u6bb5\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li>\u8054\u5408\u7d22\u5f15\u4f18\u5148\u5305\u542b\u8fc7\u6ee4\u6027\u5f3a\u7684\u5b57\u6bb5&#xff08;\u5982user_id\u6bd4status\u66f4\u9002\u5408\u4f5c\u4e3a\u7b2c\u4e00\u5217&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528<span style=\"color:#be191c\">EXPLAIN ANALYZE JSON<\/span>\u9a8c\u8bc1\u7d22\u5f15\u6709\u6548\u6027&#xff0c;\u907f\u514d\u8fc7\u5ea6\u7d22\u5f15&#xff08;\u8d85\u8fc7 5 \u4e2a\u7d22\u5f15\u7684\u8868\u9700\u8bc4\u4f30&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u76d1\u63a7\u4e0e\u9884\u8b66&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7 Prometheus&#043;Grafana \u76d1\u63a7com_select\u3001sort_merge_passes&#xff08;\u6392\u5e8f\u5408\u5e76\u6b21\u6570&#xff09;\u7b49\u6307\u6807\u3002<\/li>\n<li>\u5f53\u6162\u67e5\u8be2\u6570\u91cf\u7a81\u7136\u589e\u52a0 50% \u65f6&#xff0c;\u89e6\u53d1\u77ed\u4fe1 \/ \u90ae\u4ef6\u9884\u8b66&#xff0c;\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u603b\u7ed3<\/p>\n<p>MySQL 8 \u7684\u6162\u67e5\u8be2\u4f18\u5316\u9700\u8981\u7ed3\u5408\u7248\u672c\u7279\u6027\u4e0e\u7ecf\u5178\u4f18\u5316\u7406\u8bba&#xff0c;\u4ece \u201c\u65e5\u5fd7\u5206\u6790\u2192\u6267\u884c\u8ba1\u5212\u8bca\u65ad\u2192\u7d22\u5f15\u4f18\u5316\u2192\u7ed3\u6784\u8c03\u6574\u201d \u56db\u4e2a\u5c42\u9762\u9010\u5c42\u6df1\u5165\u3002\u901a\u8fc7EXPLAIN ANALYZE\u7684\u7cbe\u51c6\u5206\u6790\u3001\u8986\u76d6\u7d22\u5f15\u7684\u5408\u7406\u8bbe\u8ba1\u3001\u4ee5\u53ca\u5927\u8868\u62c6\u5206\u7b49\u67b6\u6784\u4f18\u5316&#xff0c;\u591a\u6570\u6162\u67e5\u8be2\u95ee\u9898\u53ef\u8fce\u5203\u800c\u89e3\u3002\u8bb0\u4f4f&#xff1a;\u4f18\u5316\u7684\u6838\u5fc3\u662f\u8ba9\u6570\u636e\u5e93 \u201c\u5c11\u5e72\u6d3b\u201d\u2014\u2014 \u51cf\u5c11\u626b\u63cf\u884c\u6570\u3001\u907f\u514d\u4e34\u65f6\u8868\u4e0e\u6587\u4ef6\u6392\u5e8f\u3001\u5229\u7528\u7d22\u5f15\u8986\u76d6\u67e5\u8be2\u3002\u6301\u7eed\u8fed\u4ee3\u4f18\u5316\u7b56\u7565\u5e76\u7ed3\u5408\u76d1\u63a7\u4f53\u7cfb&#xff0c;\u624d\u80fd\u786e\u4fdd MySQL \u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7a33\u5b9a\u9ad8\u6548\u8fd0\u884c\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb581\u6b21\uff0c\u70b9\u8d5e4\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u601d\u7ef4\u5bfc\u56fe:   \u5728 MySQL \u6570\u636e\u5e93\u7ba1\u7406\u4e2d\uff0c\u6162\u67e5\u8be2\u662f\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u7684\u5e38\u89c1\u75db\u70b9\u3002\u968f\u7740 MySQL 8 \u7248\u672c\u7684\u666e\u53ca\uff0c\u5176\u65b0\u589e\u7279\u6027\uff08\u5982 CTE\u3001\u9690\u85cf\u7d22\u5f15\u3001JSON \u683c\u5f0f\u6267\u884c\u8ba1\u5212\u7b49\uff09\u4e3a\u6162\u67e5\u8be2\u4f18\u5316\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u5de5\u5177\u3002\u672c\u6587\u7ed3\u5408 MySQL 8 \u7684\u7279\u6027\uff0c\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u8be6\u89e3\u6162\u67e5\u8be2\u7684\u5b9a\u4f4d\u3001\u5206\u6790\u4e0e\u4f18\u5316\u5168\u6d41\u7a0b\uff0c\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u6027\u80fd\u3002\u4fee\u6539 MySQL 8 \u7684\u914d\u7f6e\u6587\u4ef6my.cnf\uff08Linux\uff09\u6216my.ini\uff08Windows\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6838\u5fc3\u914d\u7f6e\uff1a\u4fee\u6539\u540e\u9700\u91cd\u542f MySQL \u670d\u52a1\u4f7f\u914d\u7f6e\u751f\u6548\u3002\u914d\u7f6e\u5b8c\u6bd5\u4e4b\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6307\u4ee4\u91cd\u65b0\u542f\u52a8MySQL\u670d<\/p>\n","protected":false},"author":2,"featured_media":35826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[114,3060,3061,100,2174],"topic":[],"class_list":["post-35828","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-mysql","tag-mysql8","tag-sql","tag-100","tag-2174"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/35828.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb581\u6b21\uff0c\u70b9\u8d5e4\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u601d\u7ef4\u5bfc\u56fe:  \u5728 MySQL \u6570\u636e\u5e93\u7ba1\u7406\u4e2d\uff0c\u6162\u67e5\u8be2\u662f\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u7684\u5e38\u89c1\u75db\u70b9\u3002\u968f\u7740 MySQL 8 \u7248\u672c\u7684\u666e\u53ca\uff0c\u5176\u65b0\u589e\u7279\u6027\uff08\u5982 CTE\u3001\u9690\u85cf\u7d22\u5f15\u3001JSON \u683c\u5f0f\u6267\u884c\u8ba1\u5212\u7b49\uff09\u4e3a\u6162\u67e5\u8be2\u4f18\u5316\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u5de5\u5177\u3002\u672c\u6587\u7ed3\u5408 MySQL 8 \u7684\u7279\u6027\uff0c\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u8be6\u89e3\u6162\u67e5\u8be2\u7684\u5b9a\u4f4d\u3001\u5206\u6790\u4e0e\u4f18\u5316\u5168\u6d41\u7a0b\uff0c\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u6027\u80fd\u3002\u4fee\u6539 MySQL 8 \u7684\u914d\u7f6e\u6587\u4ef6my.cnf\uff08Linux\uff09\u6216my.ini\uff08Windows\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6838\u5fc3\u914d\u7f6e\uff1a\u4fee\u6539\u540e\u9700\u91cd\u542f MySQL \u670d\u52a1\u4f7f\u914d\u7f6e\u751f\u6548\u3002\u914d\u7f6e\u5b8c\u6bd5\u4e4b\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6307\u4ee4\u91cd\u65b0\u542f\u52a8MySQL\u670d\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35828.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-06T09:17:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091725-6819d3a51c646.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35828.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35828.html\",\"name\":\"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-06T09:17:26+00:00\",\"dateModified\":\"2025-05-06T09:17:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35828.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35828.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35828.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/35828.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb581\u6b21\uff0c\u70b9\u8d5e4\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u601d\u7ef4\u5bfc\u56fe:  \u5728 MySQL \u6570\u636e\u5e93\u7ba1\u7406\u4e2d\uff0c\u6162\u67e5\u8be2\u662f\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u7684\u5e38\u89c1\u75db\u70b9\u3002\u968f\u7740 MySQL 8 \u7248\u672c\u7684\u666e\u53ca\uff0c\u5176\u65b0\u589e\u7279\u6027\uff08\u5982 CTE\u3001\u9690\u85cf\u7d22\u5f15\u3001JSON \u683c\u5f0f\u6267\u884c\u8ba1\u5212\u7b49\uff09\u4e3a\u6162\u67e5\u8be2\u4f18\u5316\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u5de5\u5177\u3002\u672c\u6587\u7ed3\u5408 MySQL 8 \u7684\u7279\u6027\uff0c\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u8be6\u89e3\u6162\u67e5\u8be2\u7684\u5b9a\u4f4d\u3001\u5206\u6790\u4e0e\u4f18\u5316\u5168\u6d41\u7a0b\uff0c\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u6027\u80fd\u3002\u4fee\u6539 MySQL 8 \u7684\u914d\u7f6e\u6587\u4ef6my.cnf\uff08Linux\uff09\u6216my.ini\uff08Windows\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6838\u5fc3\u914d\u7f6e\uff1a\u4fee\u6539\u540e\u9700\u91cd\u542f MySQL \u670d\u52a1\u4f7f\u914d\u7f6e\u751f\u6548\u3002\u914d\u7f6e\u5b8c\u6bd5\u4e4b\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6307\u4ee4\u91cd\u65b0\u542f\u52a8MySQL\u670d","og_url":"https:\/\/www.wsisp.com\/helps\/35828.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-06T09:17:26+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091725-6819d3a51c646.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35828.html","url":"https:\/\/www.wsisp.com\/helps\/35828.html","name":"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-06T09:17:26+00:00","dateModified":"2025-05-06T09:17:26+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35828.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35828.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35828.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6162sql\u5904\u7406\u6d41\u7a0b\u548c\u5e38\u89c1\u6848\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=35828"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35828\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/35826"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35828"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}