顺丰
MySQL慢查询定位三板斧:慢日志+EXPLAIN+索引_我的网站

A | (ECNS) -- The first-ever shipment of fresh guavas from Zhanjiang, Guangdong Province, was exported to Singapore on Tuesday, marking a new addition to the city’s fruit export portfolio. The consignment weighed 6.4 metric tons. Lianjiang, a county-level city administered by Zhanjiang, has favorable conditions for guava cultivation. The fruit has emerged as a key crop supporting rural revitalization in recent years, and Lianjiang has become China’s largest guava-producing area. Mo Lirong, head of a specialized fruit-growing farmers’ cooperative in Lianjiang, said the cooperative’s guavas are known for their thick, juicy flesh, rich aroma and high sugar content, making them popular with consumers. To facilitate the maiden export of Lianjiang guavas, Zhanjiang Customs conducted on-site inspections at local orchards to ensure product quality and safety at the source. It also opened a dedicated green channel for certificate-of-origin inspections, helping local enterprises deliver fresh produce to overseas markets more efficiently. (By Helen Mo, intern Xu Wenda)
。
一键部署OpenClaw
网站卡顿不一定是代码慢,很可能是数据库在硬扛。MySQL慢查询日志是最直接的突破口,先把执行时间长的SQL抓出来,再一条条用EXPLAIN看执行计划,最后加索引或者改写法。
开启慢日志很简单,在my.cnf里加三行,重启MySQL即可。注意long_query_time单位是秒,线上可以先设1秒,抓到明显拖后腿的语句。

B | [mysqld] slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 1 log_queries_not_using_indexes = 1
抓到慢SQL后,用EXPLAIN看type列。如果出现ALL,说明是全表扫描,必须优化。理想情况至少达到range,最好到ref或eq_ref。 EXPLAIN SELECT * FROM orders WHERE user_id = 123 AND create_time > '2026-08-01'; -- 给常用查询列加复合索引 CREATE INDEX idx_user_time ON orders(user_id, create_time);
索引不是越多越好。写操作会因为索引而变慢,而且索引文件本身也占空间。

C | 原则是高频查询、WHERE条件里的等值列优先建,范围查询列放在复合索引后面。
申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!。
Current article:http://www.kelozhaichongbaoshuo.pics/2hshfoh/20260826/32006.ppt
Published on:06:51:25



























