Skip to content

Filter empty database parameters to prevent MySQL command failures#308

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-mysqlcheck-character-set-error
Draft

Filter empty database parameters to prevent MySQL command failures#308
Copilot wants to merge 5 commits intomainfrom
copilot/fix-mysqlcheck-character-set-error

Conversation

Copy link

Copilot AI commented Feb 1, 2026

Fix Plan: mysqlcheck empty character set error

  • Understand the problem: Empty DB credentials are being passed to mysqlcheck
  • Examine the run() function to identify where empty values are added
  • Modify the run() function to skip empty string and null values
  • Add test case for empty DB_CHARSET scenario
  • Address code review feedback (handle null values, improve test assertions)
  • Run security scan with codeql_checker
  • Address additional review feedback:
    • Move filter to $final_args after merge to catch empty CLI args
    • Update test to test empty DB_HOST instead of DB_CHARSET
    • Add success message assertion for better test coverage

Summary

Successfully fixed the issue where database commands fail when DB constants are empty strings. The fix:

  1. Filter applied to $final_args after merging to catch empty values from both wp-config and CLI args
  2. Comprehensive test validates empty DB_HOST handling and verifies successful execution
  3. Benefits all db commands that use this method (check, optimize, repair, cli, query, etc.)
  4. Handles edge cases correctly (preserves '0' and 0, filters '' and null)
  5. Passes all checks: phpcs, phpstan, lint, CodeQL security scan, code review
Original prompt

This section details on the original issue you should resolve

<issue_title>mysqlcheck: Character set '' is not a compiled character set</issue_title>
<issue_description>## Bug Report
When running commands related to db at hostinger, I get the following error.

mysqlcheck: Character set '' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
Unsupported character set:

Hostinger support said it's a bug with the wp-cli, and my debug shows the same..
Describe the current, buggy behavior

When running wp db check in any of my wp installs at hostinger, I get the following:

$ wp db check
mysqlcheck: Character set '' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
Unsupported character set:

With debug...

$ wp db check --debug
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\DeclareAbstractBaseCommand (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\IncludeFrameworkAutoloader (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\ConfigureRunner (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\IncludeRequestsAutoloader (0.014s)
Debug (bootstrap): Setting RequestsLibrary::$version to v2 (0.014s)
Debug (bootstrap): Setting RequestsLibrary::$source to wp-core (0.014s)
Debug (bootstrap): Setting RequestsLibrary::$class_name to \WpOrg\Requests\Requests (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\InitializeColorization (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\InitializeLogger (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\DefineProtectedCommands (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\LoadExecCommand (0.014s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\LoadRequiredCommand (0.015s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\IncludePackageAutoloader (0.015s)
Debug (bootstrap): Processing bootstrap step: WP_CLI\Bootstrap\IncludeFallbackAutoloader (0.015s)
Debug (bootstrap): Fallback autoloader paths: phar://wp-cli.phar/vendor/autoload.php (0.015s)
Debug (bootstrap): Loading detected autoloader: phar://wp-cli.phar/vendor/autoload.php (0.015s)
Debug (bootstrap): Attaching command 'config edit' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config path' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config list' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config get' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config is-true' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config set' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config delete' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config has' to hook before_wp_load (0.022s)
Debug (bootstrap): Attaching command 'config shuffle-salts' to hook before_wp_load (0.022s)
Debug (commands): Adding command: config (0.022s)
Debug (bootstrap): Attaching command 'core download' to hook before_wp_load (0.024s)
Debug (bootstrap): Attaching command 'core version' to hook before_wp_load (0.024s)
Debug (commands): Adding command: core (0.024s)
Debug (bootstrap): Attaching command 'eval' to hook before_wp_load (0.024s)
Debug (commands): Adding command: eval (0.025s)
Debug (bootstrap): Attaching command 'eval-file' to hook before_wp_load (0.025s)
Debug (commands): Adding command: eval-file (0.025s)
Debug (commands): Adding command: cache (0.025s)
Debug (commands): Adding command: transient (0.026s)
Debug (bootstrap): Attaching command 'core verify-checksums' to hook before_wp_load (0.027s)
Debug (commands): Adding command: verify-checksums in core Namespace (0.027s)
Debug (commands): Adding command: plugin (0.027s)
Debug (commands): Adding command: verify-checksums in plugin Namespace (0.027s)
Debug (commands): Adding command: cron (0.028s)
Debug (commands): Adding command: event in cron Namespace (0.028s)
Debug (commands): Adding command: schedule in cron Namespace (0.028s)
Debug (bootstrap): Attaching command 'db' to hook after_wp_config_load (0.03s)
Debug (bootstrap): Attaching command 'db clean' to hook after_wp_load (0.031s)
Debug (bootstrap): Attaching command 'db tables' to hook after_wp_load (0.031s)
Debug (bootstrap): Attaching command 'db size' to hook after_wp_load (0.031s)
Debug (bootstrap): Attaching command 'db prefix' to hook after_wp_load (0.031s)
Debug (bootstrap): Attaching command 'db search' to hook after_wp_load (0.031s)
Debug (bootstrap): Attaching command 'db columns' to hook after_wp_load (0.031s)
Debug (commands): Adding command: db (0.032s)
Debug (commands): Adding command: embed (0.032s)
Debug (commands): Adding command: fetch in embed Namespace (0.032s)
Debug (commands...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix mysqlcheck character set error in wp-cli Filter empty database parameters to prevent MySQL command failures Feb 1, 2026
Copilot AI requested a review from swissspidy February 1, 2026 19:40
@swissspidy
Copy link
Member

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to prevent MySQL command failures by filtering out empty database parameters. The approach is sound, but the current implementation has a flaw: it filters parameters from wp-config.php before merging them with command-line arguments. This means the fix can be bypassed if an empty value is provided as a command-line argument. I've suggested applying the filter after all arguments are merged to create a more robust solution.

Additionally, the new test case for an empty DB_CHARSET doesn't actually exercise the new filtering logic due to a pre-existing condition. I've recommended an alternative test scenario that would better validate the changes.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mysqlcheck: Character set '' is not a compiled character set

2 participants