From e49ecd1203c952123b7b62b2e90390393d8f7b36 Mon Sep 17 00:00:00 2001 From: Brian Stanley Date: Thu, 7 Aug 2025 14:56:50 -0400 Subject: [PATCH] Suppress mysql warning about insecure password --- src/Commands/MigrateDumpCommand.php | 19 ++++++++++++------- src/Commands/MigrateLoadCommand.php | 6 ++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Commands/MigrateDumpCommand.php b/src/Commands/MigrateDumpCommand.php index 578badd..3a55e3f 100644 --- a/src/Commands/MigrateDumpCommand.php +++ b/src/Commands/MigrateDumpCommand.php @@ -142,14 +142,15 @@ public static function reorderMigrationRows(array $output) : array */ private static function mysqlSchemaDump(array $db_config, string $schema_sql_path) : int { - // TODO: Suppress warning about insecure password. // CONSIDER: Intercepting stdout and stderr and converting to colorized // console output with `$this->info` and `->error`. passthru( - static::mysqlCommandPrefix($db_config) + 'bash -c "' + . static::mysqlCommandPrefix($db_config) . ' --result-file=' . escapeshellarg($schema_sql_path) . ' --no-data' - . ' --routines', + . ' --routines' + . ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"', $exit_code ); @@ -170,13 +171,15 @@ private static function mysqlSchemaDump(array $db_config, string $schema_sql_pat // Include migration rows to avoid unnecessary reruns conflicting. exec( - static::mysqlCommandPrefix($db_config) + 'bash -c "' + . static::mysqlCommandPrefix($db_config) . ' ' . ($db_config['prefix'] ?? '') . 'migrations' . ' --no-create-info' . ' --skip-extended-insert' . ' --skip-routines' . ' --single-transaction' - . ' --compact', + . ' --compact' + . ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"', $output, $exit_code ); @@ -207,11 +210,13 @@ private static function mysqlSchemaDump(array $db_config, string $schema_sql_pat private static function mysqlDataDump(array $db_config, string $data_sql_path) : int { passthru( - static::mysqlCommandPrefix($db_config) + 'bash -c "' + . static::mysqlCommandPrefix($db_config) . ' --result-file=' . escapeshellarg($data_sql_path) . ' --no-create-info --skip-routines --skip-triggers' . ' --ignore-table=' . escapeshellarg($db_config['database'] . '.' . ($db_config['prefix'] ?? '') . 'migrations') - . ' --single-transaction', // Avoid disruptive locks. + . ' --single-transaction' // Avoid disruptive locks. + . ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"', $exit_code ); diff --git a/src/Commands/MigrateLoadCommand.php b/src/Commands/MigrateLoadCommand.php index 50bdba4..bf78f60 100644 --- a/src/Commands/MigrateLoadCommand.php +++ b/src/Commands/MigrateLoadCommand.php @@ -118,13 +118,15 @@ private static function mysqlLoad(string $path, array $db_config, int $verbosity // CONSIDER: Making input file an option which can override default. // CONSIDER: Avoiding shell specifics like `cat` and piping using // `file_get_contents` or similar. - $command = 'cat ' . escapeshellarg($path) + $command = 'bash -c "' + . 'cat ' . escapeshellarg($path) . ' | mysql --no-beep' . ' --host=' . escapeshellarg($db_config['host']) . ' --port=' . escapeshellarg($db_config['port'] ?? 3306) . ' --user=' . escapeshellarg($db_config['username']) . ' --password=' . escapeshellarg($db_config['password']) - . ' --database=' . escapeshellarg($db_config['database']); + . ' --database=' . escapeshellarg($db_config['database']) + . ' 2> >(grep -v \'Using a password on the command line interface can be insecure.\')"'; switch($verbosity) { case OutputInterface::VERBOSITY_QUIET: $command .= ' -q';