今日已更新 166 条资讯 | 累计 40611 条内容
关于我们

`wp db check` / `wp db optimize` — the database health commands that get overlooked

Susumu Takahashi 2026年09月01日 08:21 3 次阅读 来源:Dev.to

A WordPress database doesn't tidy itself up over time. Spam comments pile up, expired transients linger, post revisions accumulate, and tables left behind by uninstalled plugins never quite go away. All of that adds up to bloated tables, and occasionally to actual table corruption. This is territory the admin dashboard barely shows you — but WP-CLI reaches it directly with two short commands: wp db check and wp db optimize . Note: WP-CLI's wp db subcommands operate directly on the MySQL (or MariaDB) database WordPress uses, without going through the admin dashboard. Connection details are read automatically from wp-config.php . wp db check — verifying table health wp db check Under the hood, this runs the equivalent of mysqlcheck --check against every table and reports each one's status: wp_posts OK wp_options OK wp_postmeta OK If a table comes back corrupt , SELECT and INSERT queries against it start failing. That can surface as something oddly specific — a single page going blank, one particular post refusing to save — with no obvious connection to a database problem. Running wp db check on a regular schedule catches that kind of issue before it turns into a visible symptom. wp db optimize — defragmenting tables wp db optimize This one runs the equivalent of mysqlcheck --optimize , applying OPTIMIZE TABLE to each table. Tables that see a lot of row deletions and updates tend to become fragmented on disk over time. OPTIMIZE TABLE rebuilds the table and reclaims the space that deleted rows used to occupy. Note: behavior differs by storage engine. WordPress's default engine, InnoDB , handles OPTIMIZE TABLE internally as a table rebuild (roughly equivalent to ALTER TABLE ... FORCE ), which both defragments the table and refreshes its statistics. The older MyISAM engine doesn't reclaim space from deleted rows automatically at all — that disk space only gets released once OPTIMIZE TABLE runs. Some installs set up through a hosting provider's one-click installer still ca

本文内容来源于互联网,版权归原作者所有
查看原文