Loading...
X

mysqldump in PowerShell corrupts non-Latin characters when exporting database (SOLVED)

mysqldump is a MySQL utility for creating database and table backups. Unlike phpMyAdmin, which, although it offers a web interface, is a slower tool due to the limitations of intermediates such as PHP and Apache, mysqldump is a much more efficient tool without limitations for backing up very large data.

But on Windows, mysqldump has some nuances. Due to the peculiarities of PowerShell for working with encodings, all non-Latin characters can be corrupted in exported databases. This issue is not seen in CMD, but recent versions of Windows use PowerShell by default, so the issue in question affects all users who run mysqldump to back up databases in Windows.

The following command, executed in PowerShell 7:

.\mysqldump.exe -u root --all-databases > all-databases_ps7.sql

Creates a UTF-8 encoded all-databases_ps7.sql file into which all MySQL databases will be exported using mysqldump (for backup purposes). But in these databases all non-Latin characters will be irretrievably corrupted!

That is, instead of Cyrillic, it will be something like this:

'╨Р╤А╨▒╨╕╤В╤А╨░╨╢╨╜╤Л╨╣ ╨┐╤А╨╛╤Ж╨╡╤Б╤Б: ╤Г╤З╨╡╨▒╨╜╨╕╨║ / ╨Ъ.╨Ь. ╨Р╤А╤Б╨╗╨░╨╜╨╛╨▓, ╨Ф.╨е. ╨Т╨░╨╗╨╡╨╡╨▓, ╨а.╨Э. ╨У╨╕╨╝╨░╨╖╨

To avoid this problem, use mysqldump with the --result-file option. The following command will save the database in the correct encoding:

.\mysqldump.exe -u root --all-databases --result-file=all-databases.sql

You can also use the following two-command construct to fix the encoding problem:

[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("UTF-8")
.\mysqldump.exe -u root --all-databases > all-databases.sql


Leave Your Observation

Your email address will not be published. Required fields are marked *