MariaDB import issue: Error at line 1: Unknown command '\-'

Today, I tried to sync the database from the Dev server located on to my local environment using the Drush sql-sync command, and I encountered the following error:

In SqlCommands.php line 183:                                                                                                                                       
Query failed. Rerun with --debug to see any error message. ERROR at line 1: Unknown command '\-'.

Here is a screenshot of the entire error message:


Interestingly, everything worked fine until yesterday. The sync stopped working today after I did a deploy. automatically applies the latest patch version of the database during each application deployment, so I assumed the latest patch version of the minor version 10.4 was installed after the deploy.

I checked the MariaDB version on the Dev server and saw that the database version changed from 10.4.33 to 10.4.34. After researching, I found that the MariaDB team made this change for security reasons, to prevent creating database dumps that could execute shell commands. For more details, you can read about it here.

In short, the new MariaDB version adds this line to the beginning of the dump file:

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

And when such a dump is attempted to be imported locally, it results in an error.

What is the solution?

The best thing you can do is use the same version of MariaDB on your server and locally. This will fix the issue, and you will be able to sync the database using Drush. Using different versions is not a good idea anyway, so this is the option you should choose if you can.

What I did was update MariaDB from version 10.4, which is no longer supported, to the latest version 10.5. This solved my problem. You don't have to use version 10.5, of course. Update to the latest version that suits you. Just make sure it is supported, because as I mentioned, I was using version 10.4, which recently became EOL, so I couldn't use it anymore. Check supported MariaDB versions here.

If for some reason you cannot do that, you can manually export the database on the server, open the dump file in a text editor, delete the problematic line, and then manually import the database locally.

Since this issue is not just related to Drupal and Drush but to MariaDB in general, you can also use the mysql command line tool to force import without the need to first delete the problematic line from the dump. To force import the database, use the following command:

mysql -uUSERNAME -pPASSWORD --host=HOST --database=DATABASE_NAME --force < /DATABASE-DUMP.sql

Replace the values written in uppercase, then run the command to import the database.

I hope this article has helped you a bit in solving the problem.

About the Author

Goran Nikolovski is a web and AI developer with over 10 years of expertise in PHP, Drupal, Python, JavaScript, React, and React Native. He founded this website and enjoys sharing his knowledge.