惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

云心怀鹤

从2022年建站至今,一次莫名其妙的CC攻击 - 云心怀鹤 五一游记:走理小路,逛三星堆 - 云心怀鹤 bluehe.cn bluehe.cn 2026 春节叙事 - 云心怀鹤 盛世修典:广西美术馆特展 - 云心怀鹤 青秀山黄花风铃木:属于南宁绿城三月独有的浪漫 - 云心怀鹤 OpenClaw龙虾:Linux部署与QQBot对接体验 - 云心怀鹤 城市散步志:年前 - 云心怀鹤 乌托邦咖啡 南宁视角:灵龟山的落羽杉红了 千问ai的生态服务融合
Typecho优化: Mysql添加索引提高查询速度 - 云心怀鹤
云心怀鹤 · 2026-03-27 · via 云心怀鹤


叙述1109 阅29 评

我使用的数据库是mysql5.7版本,typecho创建后可以通过以下sql语句执行达到提高查询效果,执行前需快照或者备份数据库以防重要数据丢失!还有nginx与php都可以继续优化,目前我的站点除了CDN字体加载有延迟完,几乎秒开。

屏幕截图2026-03-27

1、内容表添加复合索引

ALTER TABLE `typecho_contents`  ADD INDEX `idx_type_status_created` (`type`, `status`, `created`);

2、删除默认的created 单列索引

ALTER TABLE `typecho_contents` DROP INDEX `created`;

3、评论表添加复合索引

ALTER TABLE `typecho_comments`  ADD INDEX `idx_cid_status_created` (`cid`, `status`, `created`);

4、删除单列索引

ALTER TABLE `typecho_comments` DROP INDEX `cid`;
ALTER TABLE `typecho_comments` DROP INDEX `created`;

5、用于文章与分类的关联查询

ALTER TABLE `typecho_relationships` ADD INDEX `idx_mid_cid` (`mid`, `cid`);

6、用于分类/标签的排序显示

ALTER TABLE `typecho_metas`  ADD INDEX `idx_type_order` (`type`, `order`);

完成以上三个步骤,大部分都覆盖了。

-- 查看的索引
SHOW INDEX FROM `typecho_contents`;

SHOW INDEX FROM `typecho_comments`;

SHOW INDEX FROM `typecho_relationships`;
SHOW INDEX FROM `typecho_metas`;

最后可以查看索引使用频率,看是否生效成功,总结:一个简单的联合索引就能提高很多很多速度,在我的工作中也是如此,若查询得慢,就会使用这样子的方法。

SELECT * FROM sys.schema_index_statistics 
WHERE table_schema = '数据库名称'
  AND table_name LIKE 'typecho_%'
ORDER BY rows_selected DESC;

查询出索引的索引情况,还可以把检测结果给ai,让他进一步提出优化意见。

OPTIMIZE TABLE `typecho_contents`;
OPTIMIZE TABLE `typecho_comments`;

还可以执行上面的命令,每月一次的表优化,恭喜你,完成了Typecho数据库的核心优化。