How to Handle “Table Does Not Support Optimize” Error in MySQL/WordPress Optimization


4 views

When you run OPTIMIZE TABLE on WordPress tables (especially in newer MySQL/MariaDB versions), you might encounter:

mysql> OPTIMIZE TABLE wp_posts;
+-------------+----------+----------+-------------------------------------------------------------------+
| Table       | Op       | Msg_type | Msg_text                                                          |
+-------------+----------+----------+-------------------------------------------------------------------+
| db.wp_posts | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
+-------------+----------+----------+-------------------------------------------------------------------+

This isn't an error - it's MySQL being intelligent about storage engines.

Modern WordPress installations typically use InnoDB as the default storage engine (since MySQL 5.5+). The message appears because:

  • InnoDB handles fragmentation differently than MyISAM
  • OPTIMIZE TABLE performs differently based on the storage engine
  • For InnoDB, MySQL automatically substitutes with ALTER TABLE ... FORCE + ANALYZE TABLE

Instead of using OPTIMIZE TABLE, consider these alternatives:

1. For InnoDB Tables

-- This achieves similar results to OPTIMIZE for InnoDB
ALTER TABLE wp_posts ENGINE=InnoDB;
ANALYZE TABLE wp_posts;

2. For Regular Maintenance

-- Check table status first
SHOW TABLE STATUS LIKE 'wp_posts';

-- Then analyze if needed
ANALYZE TABLE wp_posts;

For ongoing optimization, create a maintenance script:

#!/bin/bash
# WordPress DB maintenance script
DB_USER="wordpress_user"
DB_PASS="your_password"
DB_NAME="wordpress_db"

TABLES=$(mysql -u$DB_USER -p$DB_PASS $DB_NAME -e "SHOW TABLES" | awk '{ print $1}' | grep -v '^Tables' )

for t in $TABLES
do
  echo "Maintaining $t"
  mysql -u$DB_USER -p$DB_PASS $DB_NAME -e "ALTER TABLE $t ENGINE=InnoDB"
  mysql -u$DB_USER -p$DB_PASS $DB_NAME -e "ANALYZE TABLE $t"
done

Consider manual optimization only if:

  • Table size grows significantly without data increase
  • Query performance degrades noticeably
  • You've deleted large amounts of data

For non-technical users, these WordPress plugins handle optimization well:

  • WP-Optimize
  • Advanced Database Cleaner
  • WP-Sweep

When working with WordPress databases, you might encounter this message when trying to optimize tables:

mysql> OPTIMIZE TABLE wp_posts;
+---------------+----------+----------+-------------------------------------------+
| Table         | Op       | Msg_type | Msg_text                                  |
+---------------+----------+----------+-------------------------------------------+
| wordpress.wp_posts | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
+---------------+----------+----------+-------------------------------------------+

The message appears because:

  • You're using InnoDB tables (default in newer MySQL/MariaDB versions)
  • The table structure doesn't support traditional optimization
  • MySQL automatically falls back to a recreate+analyze process

For InnoDB tables (which most modern WordPress installations use), consider these approaches:

1. Using ANALYZE TABLE

ANALYZE TABLE wp_posts;

2. Table Rebuilding

For significant fragmentation:

ALTER TABLE wp_posts ENGINE=InnoDB;

3. WordPress-Specific Tools

Use WP-CLI for database maintenance:

wp db optimize
wp db repair

Here's a bash script to optimize all tables in a WordPress database:

#!/bin/bash
DB_NAME="wordpress"
DB_USER="wpuser"
DB_PASS="wppassword"

TABLES=$(mysql -u$DB_USER -p$DB_PASS $DB_NAME -e 'SHOW TABLES' | awk '{ print $1}' | grep -v '^Tables' )

for t in $TABLES
do
  echo "Optimizing $t"
  mysql -u$DB_USER -p$DB_PASS $DB_NAME -e "ALTER TABLE $t ENGINE=InnoDB; ANALYZE TABLE $t;"
done

Implement regular maintenance:

  • Schedule weekly ANALYZE operations
  • Consider using Percona Toolkit for advanced optimization
  • Monitor table fragmentation with:
SELECT TABLE_NAME, DATA_FREE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'wordpress';