powershellutf-8

correct way to Import database dump in PowerShell


Importing a database dump using cmd works properly:

tar -xf dump.zip
mysql.exe --user=Username --passsword=Password Database < dump.sql

when I try something similar in a PoweShell

Expand-Archive -Path dump.zip
Get-Content dump.sql | mysql.exe --user-Username --password=Password Database

the file gets imported but utf-8 characters in the data in the dump file are not imported as such (resulting in '??' in the data). I'm using Get-Content here as the < is currently not supported in PowerShell. If I open the dump.sql file in an editor (Notepad++) it seems to be in utf-8 format.

What would be the correct way to import the dump file?

The dump file created in mariadb 10.6.18 contains the proper settings: In the preamble:

/*!40101 SET NAMES utf8mb4 */;

Befor each table:

/*!40101 SET character_set_client = utf8 */;

Imported is in mariadb 10.6.18 The results of tar -xf and Expand-Archive are identical.


Solution

  • Preface:


    cmd /c 'mysql.exe --user=Username --passsword=Password Database < dump.sql'
    

    For background information, including about an important enhancement in PowerShell v7.4+ with respect to allowing the normally object-based pipeline situationally act like a raw byte conduit, as in cmd.exe, see this answer.