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
In Windows machine, please follows the preceding steps.
Now source your db.
May be your dump.sql is having garbage character in beginning of your file or there is a blank line in beginning.
I had the same problem, but found out that the dump file was actually a MSSQL Server backup, not MySQL.
Sometimes legacy backup files play tricks on us. Check your dump file.
On terminal window:
~$ cat mybackup.dmp
The result was:
TAPE??G?"5,^}???Microsoft SQL ServerSPAD^LSFMB8..... etc...
To stop processing the cat command:
CTRL + C
Your File should be only .sql extension, (.zip, .gz .rar) etc will not support. example: dump.sql
Under linux Ungzip your file using gunzip Edit your unzip sql file using
vi unzipsqlfile.sql
Remove the first binary line with esc dd go to the bottom of the file with esc shift g remove the last binary line with dd save the file esc x: Then reimport to mysql with :
mysql -u username -p new_database < unzipsqlfile.sql
I performed that with a 20go sql file from a jetbackup cpanel mysql backup. Be patient to wait vi doing the job for big files
I know the original posters question was solved, but I came here via Google, and the various answers eventually led me to discovering that my SQL was dumped with a different default charset than the one used to import it. I got the same error as the original question, but as our dump was piped into another MySQL client, we couldn't go the route of opening it with another tool and saving it differently.
For us, the solution turned out to be the --default-character-set=utf8mb4
option, to be used both on the call of mysqldump
as well as the call to import it via mysql
. Of course, the value of the parameter may differ for others facing the same problem, it's just important to keep it the same, as the servers (or the tools) default setting might be any charset.