@@ -250,7 +250,12 @@ public function clean( $_, $assoc_args ) {
250250 */
251251 public function check ( $ _ , $ assoc_args ) {
252252
253- $ command = sprintf ( '/usr/bin/env mysqlcheck%s %s ' , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
253+ $ command = sprintf (
254+ '/usr/bin/env %s%s %s ' ,
255+ $ this ->get_check_command (),
256+ $ this ->get_defaults_flag_string ( $ assoc_args ),
257+ '%s '
258+ );
254259 WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
255260
256261 $ assoc_args ['check ' ] = true ;
@@ -293,8 +298,12 @@ public function check( $_, $assoc_args ) {
293298 * Success: Database optimized.
294299 */
295300 public function optimize ( $ _ , $ assoc_args ) {
296-
297- $ command = sprintf ( '/usr/bin/env mysqlcheck%s %s ' , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
301+ $ command = sprintf (
302+ '/usr/bin/env %s%s %s ' ,
303+ $ this ->get_check_command (),
304+ $ this ->get_defaults_flag_string ( $ assoc_args ),
305+ '%s '
306+ );
298307 WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
299308
300309 $ assoc_args ['optimize ' ] = true ;
@@ -337,8 +346,12 @@ public function optimize( $_, $assoc_args ) {
337346 * Success: Database repaired.
338347 */
339348 public function repair ( $ _ , $ assoc_args ) {
340-
341- $ command = sprintf ( '/usr/bin/env mysqlcheck%s %s ' , $ this ->get_defaults_flag_string ( $ assoc_args ), '%s ' );
349+ $ command = sprintf (
350+ '/usr/bin/env %s%s %s ' ,
351+ $ this ->get_check_command (),
352+ $ this ->get_defaults_flag_string ( $ assoc_args ),
353+ '%s '
354+ );
342355 WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
343356
344357 $ assoc_args ['repair ' ] = true ;
@@ -611,7 +624,7 @@ public function export( $args, $assoc_args ) {
611624 $ assoc_args ['result-file ' ] = $ result_file ;
612625 }
613626
614- $ mysqldump_binary = Utils \force_env_on_nix_systems ( ' mysqldump ' );
627+ $ mysqldump_binary = Utils \force_env_on_nix_systems ( $ this -> get_dump_command () );
615628
616629 $ support_column_statistics = exec ( $ mysqldump_binary . ' --help | grep "column-statistics" ' );
617630
@@ -2152,4 +2165,22 @@ protected function get_current_sql_modes( $assoc_args ) {
21522165
21532166 return $ modes ;
21542167 }
2168+
2169+ /**
2170+ * Returns the correct `check` command based on the detected database type.
2171+ *
2172+ * @return string The appropriate check command.
2173+ */
2174+ private function get_check_command () {
2175+ return ( strpos ( Utils \get_mysql_version (), 'MariaDB ' ) !== false ) ? 'mariadb-check ' : 'mysqlcheck ' ;
2176+ }
2177+
2178+ /**
2179+ * Returns the correct `dump` command based on the detected database type.
2180+ *
2181+ * @return string The appropriate dump command.
2182+ */
2183+ private function get_dump_command () {
2184+ return ( strpos ( Utils \get_mysql_version (), 'MariaDB ' ) !== false ) ? 'mariadb-dump ' : 'mysqldump ' ;
2185+ }
21552186}
0 commit comments