Drush sql:sync Error at line 1: Unknown command '\-'

donderdag 6 juni 2024 - 592 woorden, 3 min read

The Drush sql:sync and sql:cli commands stopped working and here is why (it applies to the latest MariaDB server versions).

After I updated the MariaDB server version to 10.11.8 on one of my servers, the drush sql:sync command stopped working (I’m using drush sql-sync @source @target). This is the error returned: ERROR at line 1: Unknown command '\-'.

Here is the full output of the command:

The command "/var/www/vendor/bin/drush sql:query --strict=0 --file=/tmp/drplrefresh_drupal_20240606_080604.sql.gz --file-delete --uri=defa  
  ult" failed.                                                                                                                       
  Exit Code: 1(General error)                                                    
  Working directory:                                                                                                                          
  Error Output:                                                                                                                               
  In SqlCommands.php line 183:                                                                                                                
    Query failed. Rerun with --debug to see any error message. ERROR at line 1:                                                               
     Unknown command '\-'. 

The same error was returned when I tried to import a manually created database dump file with drush sql-cli:

$ vendor/bin/drush sql-cli < dump.sql -v
 [info] Starting bootstrap to max
 [info] Drush bootstrap phase: bootstrapDrupalRoot()
 [info] Change working directory to /var/www/web
 [info] Initialized Drupal 10.2.6 root directory at /var/www/web
 [info] Drush bootstrap phase: bootstrapDrupalSite()
 [info] Initialized Drupal site default at sites/default
 [info] Drush bootstrap phase: bootstrapDrupalConfiguration()
 [info] Executing: command -v mysql
 [info] Executing: mysql --defaults-file=/tmp/drush_YRDbM2 --database=drplrefresh_drupal --host=drplrefresh_db --port=3306 -A
> ERROR at line 1: Unknown command '\-'.
 [info] fwrite(): Write of 4096 bytes failed with errno=32 Broken pipe AbstractPipes.php:126

In Process.php line 270:
  The command "mysql --defaults-file=/tmp/drush_YRDbM2 --database=drplrefresh  
  _drupal --host=drplrefresh_db --port=3306 -A" failed.                        
  Exit Code: 1(General error)                                                  
  Working directory: /var/www/web                                              
  Error Output:                                                                
  ERROR at line 1: Unknown command '\-'.                                       

Exception trace:
  at /var/www/vendor/symfony/process/Process.php:270
 Symfony\Component\Process\Process->mustRun() at /var/www/vendor/drush/drush/src/Commands/sql/SqlCommands.php:144
 Drush\Commands\sql\SqlCommands->cli() at n/a:n/a
 call_user_func_array() at /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:276
 Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback() at /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:212
 Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter() at /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:175
 Consolidation\AnnotatedCommand\CommandProcessor->process() at /var/www/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:387
 Consolidation\AnnotatedCommand\AnnotatedCommand->execute() at /var/www/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/symfony/console/Application.php:1096
 Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /var/www/vendor/drush/drush/src/Runtime/Runtime.php:110
 Drush\Runtime\Runtime->doRun() at /var/www/vendor/drush/drush/src/Runtime/Runtime.php:40
 Drush\Runtime\Runtime->run() at /var/www/vendor/drush/drush/drush.php:139
 require() at /var/www/vendor/drush/drush/drush:4
 include() at /var/www/vendor/bin/drush:119

It seems to be in issue in the MariaDB server, so it’s not related to Drupal or Drush. The known issue: https://jira.mariadb.org/browse/MDEV-34183 which describes that the mariadb-dump is adding the line /*!999999\- enable the sandbox mode */ at the beginnen of the dump file. I found this explanation here:

Note: From MariaDB 10.5.25MariaDB 10.6.18MariaDB 10.11.8MariaDB 11.0.6MariaDB 11.1.5MariaDB 11.2.4 and MariaDB 11.4.2 mariadb-dump generates a command at the beginning of the dump to enable sandbox mode. This command cannot be interpreted by earlier versions of the MariaDB command line client or by MySQL’s command line client, and the client will generate an error if used against the versions that do not support it. This does not affect other methods of importing the data.

It’s also explained on this blog https://mariadb.org/mariadb-dump-file-compatibility-change/ provided with solutions.


Recommended: Import the dump using the secure client from a version of MariaDB Server that has the change.

This mean you need to update your MariaDB server on every instance.

This recommended solution won’t work for everyone to get ahead in your work. As I’m not the first and only one running into this issue, I found following solution (workaround) for the moment. Open the database dump file in a text editor and delete the following line at the begin:

/*!999999\- enable the sandbox mode */

Save file and run the drush sql-cli command again.

As for the drush sql-sync @target @source we have to wait for a (backwards-compatible) solution provided by the Drush package. As far as I can see, there is no issue created on this yet in the Github repository.

The recommended solution would be to update my local Docker MariaDB image to the latest 10.11 version (I’m using version 10.11.8 at this moment). This also means I need to recreate all the containers in different projects which are using this image and do some addition cleanup as well.

Other resources

Sebastian Hagens @Sebastix
I work as creative webdeveloper & tech consultant and care about digital freedoms. Follow me:
or visit my contact page