I am trying to import a mysqldump file via the command line, but continue to get an error. I dumped the file from my other server using:
mysqldump -u XXX -p database_name > database.sql
Then I try to import the file with:
mysql -u XXX -p database_name < database.sql
It loads a small portion and then gets stuck. The error I receive is:
ERROR at line 1153: Unknown command '\''.
I checked that line in the file with:
awk '{ if (NR==1153) print $0 }' database.sql >> line1153.sql
and it happens to be over 1MB in size, just for that line.
Any ideas what might be going on here?
You have binary blobs in your DB, try adding --hex-blob to your mysqldump statement.
You know what's going on - you have an extra single quote in your SQL!O
If you have 'awk', you probably have 'vi', which will open your line1153.sql file with ease and allow you to find the value in your database that is causing the problem.
Or... The line is probably large because it contains multiple rows. You could also use the --skip-extended-insert option to mysqldump so that each row got a separate insert statement.
Good luck.
I had the same problem because I had Chinese characters in my datasbase. Below is what I found from some Chinese forum and it worked for me.
mysql -u[USERNAME] -p[PASSWORD] --default-character-set=latin1
[DATABASE_NAME] < [BACKUP_SQL_FILE.sql]
I think you need to use path/to/file.sql instead of path\to\file.sql
Also, database < path/to/file.sql didn't work for me for some reason - I had to use use database; and source path/to/file.sql;.
If all else fails, use MySQLWorkbench to do the import. This solved the same problem for me.
I recently had a similar problem where I had done an sql dump on a Windows machine and tried to install it on a Linux machine. I had a fairly large SQL file and my error was happening at line 3455360. I used the following command to copy all text up to the point where I was getting an error:
sed -n '1, 3455359p' < sourcefile.sql > destinationfile.sql
This copied all the good code into a destination file. I looked at the last few lines of the destination file and saw that it was a complete SQL command (The last line ended with a ';') so I imported the good code and didn't get any errors.
I then looked at the rest of the file which was about 20 lines. It turns out that the export might not have completed b/c I saw the following php code at the end of the code:
Array
(
[type] => 1
[message] => Maximum execution time of 300 seconds exceeded
[file] => C:\xampp\htdocs\openemr\phpmyadmin\libraries\Util.class.php
[line] => 296
)
I removed the offending php code and imported the rest of the database.
I had special character in table names , like _\ and it give error when try to import that tables.
i fixed it by changing \ to \\ in dumped sql.
my table names where like rate_\ and i used this command to repair dump :
sed 's._\\._\\\\.g' dump.sql > dump2.sql
i didn't replace all backslashes , because i was not sure if there is some backslash somewhere in database that should not be replaces.
special characters in table name will be converted to # at sign in file name.
read http://dev.mysql.com/doc/refman/5.5/en/identifier-mapping.html
I have same error as,
Unknown command '\▒'.
when I ran this
mysql -u root -p trainee < /xx/yy.gz
So I'd followed these answers. But I did not got the restored db trainee. Then found that
yy.gz is zip file. So I restoring after unzip the file as:
mysql -u root -p trainee < /xx/yy.sql
Related
I am trying input datadump to mysql.5.7.19.
I command like below :
mysql -uroot -p temp < temp201708.sql
my my.cnf prints error to /var/log/mysqld.log, but I do not see any error log while dumping.
However, when jobs done, I can not find any tables or data in temp schema. I think I saw some articles that different mysql versions could be a problem. Is it right?
Currently, I do not know what point is wrong, since there were no error log. What should I look for to solve this problem?
Thanks.
FYI, I do not know what version of mysql which made that dump file, I just received from the client.
mysqldump -u root -p DatabaseName > /Path-To-put-The-File/fileName.sql
When doing a dump in mysql:
run cmd
locate location of your mysql server like
Enter:
cd C:\Program Files\MySQL\MySQL Server 5.6\bin
mysqldump -uUsernameHere -pYourPasswordHere dbnamehere > "D:\sample.sql" make sure you have a drive D: in your computer or you can change it.
This is working and tested.
You can use it by calling a .bat file to execute the command.
Otherwise if you want to store a data into your Database use mysql only and not mysqldump and change > to <
like this:
mysql -uUsernameHere -pYourPasswordHere dbnamehere < "D:\sample.sql"
Thanks for answers.
I found the cause.
In the dump file, there are some states like USE mysql;, USE temp;.
So even though I indicate which schema to put in in command line,
it just ignore the command line and follow the script.
I found all of my data in mysql schema.
==========================
Conclusion
if you dump with some command like below
$ > mysqldump -u[user] -p[passwd] [scheme] > dump.sql
it is ok with
$ > mysql -u[user] -p[passwd] [target_scheme] < dump.sql
If not, you should check the contents of .sql file.
I successfully created a mysqldump file myDump.sql of a myDb1 database using guidelines from this thread. Also I created a second database myDb2, navigated to the directory containing myDump.sql and trying to restore it into the new database myDb2 but failing, Two methods I tried:
> mysql -u root -p myDb2 < myDump.sql;
> -- entered password
and:
> mysql -u root -p
mysql> -- entered password
mysql> USE myDb2;
mysql> SOURCE myDump.sql;
Both have the same error message:
ERROR:
ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in
non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: ' ■-'.
I'd also like to know if I need to use the same database name as the old db for the new one. I tried with a different and same names, but with this same result error.
This is probably caused by coding systems.
My dump file is generated using redirection (">") in powershell and I encountered the same problem. The output redirection generated a file with UTF-16 Little endian.
However, this can be solved by converting the dumpfile into utf-8. This can be done in emacs as:
M-x set-buffer-file-coding-system
Then save the file and import again.
The coding system of a file can be detected using GNU "file" utility, and it also available in windows and can be found here: http://gnuwin32.sourceforge.net/packages/file.htm
For future use, a better dump command like:
mysqldump <dbname> -r <filename>
Check the myDump.sql file, it maybe a coding error in the file. These garbage characters cause this problem. Delete the garbage characters to solve the issue.
Open with Sequel Pro shows this
`í}k¯]ÇÝçðWÜ?øy«««_%c�sè;¶`Ìô hãEE¤"8Áü÷ô>ûqzW¯:êmX0`²¸yyëÔºµë¹êGw?û+þ{ð£»g¯ÿçw¯¿ºû/ß¾¹{ö/ï^}÷§oªô__ûöË7_ß'éÁªà¿¿{÷ÍÇ}ôý÷ßOo/ãoßL_¼ùÓG×?ûâÍ«×Óß¼ùãW¯/òÍGË?`
I'm on a japanese system using xampp. This is the line I use to dump my database.
c:\xampp\mysql\bin>mysqldump.exe -uroot wp_newsja > dump.sql
Then I create a database on another server.
c:\xampp\mysql\bin>mysqladmin -uroot create db
But when I try to execute the sql...
c:\xampp\mysql\bin>mysql -uroot db < dump.sql
... I get the following error.
ERROR at line 145: Unknown command '¥''.
On a japanese computer windows path slashes / are represented with "¥". Which leads me to believe this is an utf8 issue. Maybe there is a way I can mysqldump with some utf8 flag? Thanks for any assistance! The exported sql is here: http://goo.gl/7MPVG - Error at line 145:
edit: Problem solved:
mysql --default-character-set=utf8 db < dump.sql
Sorry if I wasted anyone's time.
mysql --default-character-set=utf8 db < dump.sql
You can add this argument --default-character-set=utf8 in the command:
mysql -u USERNAME -p my_database --default-character-set=utf8 < "C:/My Document Names Have Spaces/my_dump.sql"
I've finally found this solution and it works fine with my new installed WampServer 2.5. I've also tried to add the default character setting in my.ini, but it's useless. Until I've tried the above argument added in my DOS batch file.
My batch file execute the command, like this way:
7zip x -so %1.%2.7z|%mysql% -uxxxx -pyyyyy %2 --default-character-set=utf8
For example, the 7zip filename is 20141231.google.7z, which contains "google.sql", and the database name is google
My backup process on Linux system was a 7zip compressed. In Winodws, I used an automatic batch file to restore the same contents, so that I can share the same database in my biz trip and work offline from the server.
Hope this method is helpful to you.
mysqldump -u(username) -p(password) --no-data --quick
--skip-add-drop-table --replace (database_name) authors_main
getting commond not found error while trying to run above command on UNIX. (this used to work completely fine a month back)
Thanks for all the help in anticipation
Maybe you should check whether your password has special characters like ! or # or # etc and make sure they are not wrongly interpreted by shell
I have a MySQL file, db.sql. I have tried to import it using:
mysql -uroot -p[password] db < db.sql
All I get is a listing of mysql commands, or I get a syntax error. The weird thing is I used this file last week and, as far as I know, I'm doing it the same way.
I create the database, then in command line enter the above but it's not working. I've tried being inside mysql and just at command line and nothing seems to be working.
Is there something I should be doing differently in windows or MySQL5? I don't know how the heck I got it to work the first time...
TIA
Try this instead:
mysql -u root -p
(prompts for password)
use db;
source db.sql
I found out it is different to run this command from Windows Command Line (cmd.exe) and Windows PowerShell.
Using CMD.exe the command works okay, but in PowerShell I get this error:
mysql -uroot exampledb < exampledb.sql
The '<' operator is reserved for future use.
Not sure if your example was a typo or not, but for starters you need to have a space in between your flags and their values, roughly like this:
mysql -u root -p [password] db < db.sql
If you are already logged in the try this it will be very useful, but depend upon the MySQL version, it works on MySQL 5.0
For log in if you are not already logged in.
mysql>[your password]
Other wise, use the database to which you want to import the SQLDump file by command.
mysql>use [your database name]
And then give source the database Dump file path as blow command(If not works the copy Dump database file to the bin folder where the MySQL installed for eg. "C:/programfiles/mysql/mqlserver5.0/bin")
mysql> source [dataBasePath+name.sql or dataBaseName.sql]
I've been using PHP script called "BigDump":
http://www.ozerov.de/bigdump.php
This perfectly works
mysql>[your password]
Other wise, use the database to which you want to import the SQLDump file by command.
mysql>use [your database name]
And then give source the database Dump file path as blow command(If not works the copy Dump database file to the bin folder where the MySQL installed for eg. "C:/programfiles/mysql/mqlserver5.0/bin")
mysql> source [dataBasePath+name.sql or dataBaseName.sql]EG: source C:.....sql
I am using mysql server 5.5
In Windows PowerShell, you can pipe in the contents like so:
Get-Content db.sql | mysql -u root -p [password]