Search code examples
powershellio-redirection

How to import Data from a MariaDB Dump-File with Windows PowerShell


Im trying to import a dumpfile.sql in the Windows Powershell with:

mysql -u root -p --database=database < Backup.sql

but i get the following error:

At <script-path>:1 char:34
+ mysql -u root -p --database=database < Backup.sql
+                                      ~ 
The '<' operator is reserved for future use..
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

If i try to escape the "<"

mysql -u root -p --database=database ^< Backup.sql

I only get a list of all options.

Maybe the problem arose due to the update to Windows 11.


Solution

  • Did you try to pipe the backup file to the mysql exe like this:

    Get-Content 'Backup.sql' | mysql.exe -u root -p --database=database
    

    Another option is to run it using cmd from powershell

    & cmd /c "mysql.exe -u root -p --database=database < backup.sql"