I am extremely new to MySQL and am running it on Windows. I am trying to restore a Database from a dumpfile in MySQL, but I get the following error:
$ >m
Old but gold!
On MacOS (Catalina 10.15.7) it was a bit weird:
I had to rename my dump.sql
into dump.zip
and after that, i had to use finder(!) to unzip it.
in terminal, unzip dump.zip
oder tar xfz dump.sql[or .gz .tar ...]
leads to error msgs.
Finally, finder has unziped it totally fine, after that i could import the file without problems.
You can use this to fix error:
zcat {address_sql_database(.tar.gz)} | mysql -u root -p {database_name} --binary-mode
I meet the same problem in windows restoring a dump file. My dump file was created with windows powershell and mysqldump like:
mysqldump db > dump.sql
The problem comes from the default encoding of powershell is UTF16. To look deeper into this, we can use "file" utility of GNU, and there exists a windows version here.
The output of my dump file is:
Little-endian UTF-16 Unicode text, with very long lines, with CRLF line terminators.
Then a conversion of coding system is needed, and there are various software can do this. For example in emacs,
M-x set-buffer-file-coding-system
then input required coding system such as utf-8.
And in the future, for a better mysqldump result, use:
mysqldump <dbname> -r <filename>
and then the output is handled by mysqldump
itself but not redirection of powershell.
reference: https://dba.stackexchange.com/questions/44721/error-while-restoring-a-database-from-an-sql-dump
Unzip the file, and then import again.
zcat /path/to/file.sql.gz | mysql -u 'root' -p your_database
Have you tried opening in notepad++ (or another editor) and converting/saving us to UTF-8?
See: notepad++ converting ansi encoded file to utf-8
Another option may be to use textwrangle to open and save the file as UTF-8: http://www.barebones.com/products/textwrangler/