Search code examples
mysqlwordpressmariadbwp-climysqlcheck

WP CLI Claims DB Needs Repairing but WP Itself Works


I use wp-cli in my deploy/upgrade script. I'm currently getting the following error from wp core is-installed (first command my script does with wp cli)

Error: One or more database tables are unavailable. The database may need to be repaired.

So I ran mysqlcheck --all-databases --check --extended to see what the DB error was but it reports that all tables are OK!

Also, the site itself seems to work (can log in to admin, view pages, etc.) so it feels like this a wp-cli issue on the one hand, but coming from wp core or the DB on the other.

Does anyone have any ideas where I can start looking? Nothing in apache logs except some warnings that we always get.

Running WordPress 5.4.2 and wp-cli 2.4.0. The first time the error came, we hadn't run the "upgrade" routine after updating WP version earlier, but I went in to admin and clicked "Upgrade Network". This succeeded but the cli still fails.

Database is 10.4.13-MariaDB and PHP version is 7.3.19. Running on CentOS Linux.

Checked the mariadb.log (thanks @nbk). Nothing comes when running the site or the wp-cli command. However, when i run the mysqlcheck command I get some errors like:

[ERROR] InnoDB: index records in a wrong order in option_name of table myschema.wp_options

I think I'll try and export/re-import of the whole schema


Solution

  • It seems that the DB had somehow got a mixture of utf8 and utf8mb4 tables. Not sure how. I would speculate that it might be those created before and after upgrade of MariaDb version but not sure that's true. Anyway, we solved by exporting the whole schema, fixing the collations in the dump file and re-importing.

    If there's a bug, I'd say it's in the mysqlcheck command, which reported everything as OK, even while it was triggering errors in the mariadb.log about the records being malformed.