From 8197a54afedad506e220f823725b1e0517e9c28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Tue, 12 May 2026 15:35:13 +0300 Subject: [PATCH 1/3] Use `Utils\get_mysql_binary_path()` to get correct binary --- src/DB_Command.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DB_Command.php b/src/DB_Command.php index 75309042..7d1e92d0 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -2369,9 +2369,13 @@ protected function get_current_sql_modes( $assoc_args ) { /** * Returns the correct `mysql` command based on the detected database type. * - * @return string The appropriate check command. + * Delegates to get_mysql_binary_path() which already probes for the MariaDB + * binary and falls back to MySQL when not available. + * + * @return string The appropriate mysql command. */ private function get_mysql_command() { - return 'mariadb' === Utils\get_db_type() ? 'mariadb' : 'mysql'; + $path = Utils\get_mysql_binary_path(); + return '' !== $path ? basename( $path ) : 'mysql'; } } From becba050a89bb3384553cc2457e2425f3cd01113 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 1 Jul 2026 16:26:55 +0200 Subject: [PATCH 2/3] Directly use `Utils\get_mysql_binary_path()` as-is --- src/DB_Command.php | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/DB_Command.php b/src/DB_Command.php index 3aebdbda..057b943c 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -472,8 +472,8 @@ public function cli( $_, $assoc_args ) { } $command = sprintf( - '/usr/bin/env %s%s --no-auto-rehash', - $this->get_mysql_command(), + '%s%s --no-auto-rehash', + Utils\get_mysql_binary_path(), $this->get_defaults_flag_string( $assoc_args ) ); WP_CLI::debug( "Running shell command: {$command}", 'db' ); @@ -593,8 +593,8 @@ public function query( $args, $assoc_args ) { } $command = sprintf( - '/usr/bin/env %s%s --no-auto-rehash', - $this->get_mysql_command(), + '%s%s --no-auto-rehash', + Utils\get_mysql_binary_path(), $this->get_defaults_flag_string( $assoc_args ) ); WP_CLI::debug( "Running shell command: {$command}", 'db' ); @@ -837,7 +837,7 @@ private function get_posts_table_charset( $assoc_args ) { list( $stdout, $stderr, $exit_code ) = self::run( sprintf( '%s%s --no-auto-rehash --batch --skip-column-names', - $this->get_mysql_command(), + Utils\get_mysql_binary_path(), $this->get_defaults_flag_string( $assoc_args ) ), [ 'execute' => $query ], @@ -945,8 +945,8 @@ public function import( $args, $assoc_args ) { } $command = sprintf( - '/usr/bin/env %s%s --no-auto-rehash', - $this->get_mysql_command(), + '%s%s --no-auto-rehash', + Utils\get_mysql_binary_path(), $this->get_defaults_flag_string( $assoc_args ) ); WP_CLI::debug( "Running shell command: {$command}", 'db' ); @@ -1939,7 +1939,7 @@ protected function run_query( $query, $assoc_args = [] ) { self::run( sprintf( '%s%s --no-auto-rehash', - $this->get_mysql_command(), + Utils\get_mysql_binary_path(), $this->get_defaults_flag_string( $assoc_args ) ), array_merge( [ 'execute' => $query ], $mysql_args ) @@ -2337,7 +2337,7 @@ protected function get_current_sql_modes( $assoc_args ) { list( $stdout, $stderr, $exit_code ) = self::run( sprintf( '%s%s --no-auto-rehash --batch --skip-column-names', - $this->get_mysql_command(), + Utils\get_mysql_binary_path(), $this->get_defaults_flag_string( $assoc_args ) ), array_merge( $args, [ 'execute' => 'SELECT @@SESSION.sql_mode' ] ), @@ -2365,17 +2365,4 @@ protected function get_current_sql_modes( $assoc_args ) { return $modes; } - - /** - * Returns the correct `mysql` command based on the detected database type. - * - * Delegates to get_mysql_binary_path() which already probes for the MariaDB - * binary and falls back to MySQL when not available. - * - * @return string The appropriate mysql command. - */ - private function get_mysql_command() { - $path = Utils\get_mysql_binary_path(); - return '' !== $path ? basename( $path ) : 'mysql'; - } } From 8b069c7caa88be24287e1e582af04841a50c1453 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 6 Jul 2026 13:52:02 +0200 Subject: [PATCH 3/3] Update tests --- features/db-import.feature | 6 +++--- features/db-query.feature | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/db-import.feature b/features/db-import.feature index 8438d06b..d1ba3348 100644 --- a/features/db-import.feature +++ b/features/db-import.feature @@ -155,13 +155,13 @@ Feature: Import a WordPress database Then the wp_cli_test.sql file should exist When I try `wp db import --defaults --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-auto-rehash# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-auto-rehash# When I try `wp db import --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash# When I try `wp db import --no-defaults --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash# @require-mysql-or-mariadb Scenario: Import db that has emoji in post diff --git a/features/db-query.feature b/features/db-query.feature index 48a50af5..07b5a262 100644 --- a/features/db-query.feature +++ b/features/db-query.feature @@ -83,13 +83,13 @@ Feature: Query the database with WordPress' MySQL config Given a WP install When I try `wp db query --defaults --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-auto-rehash# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-auto-rehash# When I try `wp db query --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash# When I try `wp db query --no-defaults --debug` - Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash# + Then STDERR should match #Debug \(db\): Running shell command: /([^/]+/)+(mysql|mariadb) --no-defaults --no-auto-rehash# Scenario: SQL modes do not include any of the modes incompatible with WordPress Given a WP install