Enable binary mode while restoring a Database from an SQL dump

后端 未结 17 1633
耶瑟儿~
耶瑟儿~ 2020-12-07 14:41

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         


        
相关标签:
17条回答
  • 2020-12-07 14:55

    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.

    0 讨论(0)
  • 2020-12-07 14:56

    You can use this to fix error:

    zcat {address_sql_database(.tar.gz)} | mysql -u root -p {database_name} --binary-mode
    
    0 讨论(0)
  • 2020-12-07 15:03

    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

    0 讨论(0)
  • 2020-12-07 15:07

    Unzip the file, and then import again.

    0 讨论(0)
  • 2020-12-07 15:08

    zcat /path/to/file.sql.gz | mysql -u 'root' -p your_database

    0 讨论(0)
  • 2020-12-07 15:10

    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/

    0 讨论(0)
提交回复
热议问题