I am trying to backup and restore the cleardb database. I was trying to backup to my local computer first and then restore it. However, I am not able to create a backup
mysqldump -h us-csdr-fern-sds-03.cleardb.net -u sdloremipsum5 -p ipsum <my_dev_dump.sql
I am trying this from mysql shell but I get
Syntax Error: Unexpected Identifier
use
mysqldump -u username -p databasename > filename.sql
to export and
mysql -u username -p databasename < filename.sql
to import
Please refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
Duplicate: Syntax error in mysqldump command
Answer: https://stackoverflow.com/a/18502626/10368530
I was trying to backup a MySQL database via command line and I typed
mysql -u -root -p -h server.com DATABASE > file.sql
INSTEAD OF
mysqldump -u -root -p -h server.com DATABASE > file.sql
It created a file on my desktop so I thought it was working and I left it for about an hour.
I then realized that it still wasn't finished, pressed ctrl + c to kill it.
I then opened file.sql and there was nothing in it.
What just happened? Did I just corrupt my database?
I have a mysql dump file named dblp.sql
I am trying to restore it to database named DBLP
I tried the command:
source dblp.sql
mysql -u root -p -h localhost DBLP < dblp.sql
And those did not work. I keep getting an error SQL syntax on the second command. And failed to open file on the first command.
Any help would be really appreciated thank you.
Try restoring the data using the 'force' flag. One of the server's I helped maintain did not like to restore it's dump'ed data.
mysql -u root -p -h localhost DBLP --force < dblp.sql
try
mysql -hlocalhost -uroot DBLP < dblp.sql
I have .sql files that I'm guessing is auto-generated. I did not generate this file, but anyway it includes the database name and all tables with fields. I'd like to add the db and tables to my mysql localhost and would like to know how to do this. I have tried uploading the file but keep getting errors about my sql syntax. The syntax looks all correct to me so perhaps the .sql file needs to be changed?
From command-line:
mysql -u root -p databaseName < file.sql
Where databaseName is an already created empty database and file.sql is the .sql file you have, you must be in the same folder as the file when you run the command. This also assumes using root as the user and that it is password protected. Modify as needed for your own setup.
Additionally, you can do the reverse by flipping the angled bracket to create a database dump to a file. Like below.
mysql -u root -p databaseName > file.sql
To IMPORT:
ype the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using vivek as username:
$ mysql -u sat -p -h localhost blog < data.sql
If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql
Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
If you want a GUI tool then you could probably use SQLyog or navicat for this.
You also can use a GUI tool - dbForge Studio for MySQL to execute the script. The SQL syntax check option will highlight syntax errors automatically, on file opening.
I have this command:
mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql
But I get the following error:
Error
unknow command '\U'
unknow command '\m'
unknow command '\D'
unknow command '\L'
For those using a Windows OS, I was able to import a large mysqldump file into my local XAMPP installation using this command in cmd.exe:
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql
Also, I just wrote a more detailed answer to another question on MySQL imports, if this is what you're after.
Go to the xampp shell command line
and run
mysql -h localhost -u username databasename < dump.sql
You may also need to specify the host. From your statement, it looks like you run on Windows. Try this:
mysql -h localhost -u #myusername -p #mypasswd MYBASE
< c:/user/folderss/myscript.sql
Or
mysql -h localhost -u #myusername -p #mypasswd MYBASE
< "c:\user\folderss\myscript.sql"
mysql -h localhost -u username databasename < dump.sql
It works, try it.
If password is blank no need to add the -p args.
/opt/lampp/bin/./mysql -u dbusername -p dbname < sqlfilepath.sql
It works:
mysql -u root -p db_name < "C:\folder_name\db_name.sql"
C:\ is for example
Copy Database Dump File at (Windows PC)
D:\xampp\mysql\bin
mysql -h localhost -u root Databasename <#data11.sql
this command posted by Daniel works like charm
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql
just put the db username and db name without those backets
**NOTE: Make sure your database file is reside inside the htdocs folder, else u'll get an Access denied error
No Doubt It does the trick:
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql
But some time you many find "MySql Server has Gone a way"
For that you need to change mysql/bin/my.ini max_allowed_packet = 64M to my.ini
I think the commands are OK, issue is with the spaces.
Please observe the spaces between -u and #myusername also between -p and #mypasswd.
mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql
Can also be written as:
mysql -u#myusername -p#mypasswd MYBASE < c:\user\folderss\myscript.sql
Also, you need not add -p and the time of command, if your password is blank, it will not ask you for the password.
If you have password to your database, it will ask for the password.
Thanks
The process is simple-
Move the database to the desired folder e.g. /xampp/mysql folder.
Open cmd and navigate to the above location
Use command to import the db - "mysql -u root -p dbpassword newDbName < dbtoimport.sql"
Check for the tables for verification.
In Windows, place the MySQL file (i.e. example.sql) in C:\xampp\mysql\bin.
Open the XAMPP Control Panel, and launch Shell:
cd c:\xampp\mysql\bin
mysql --default-character-set=utf8 -h localhost -u username databasename < example.sql
Note: Using --default-character-set=utf8 can help to prevent encoding issues with special characters if you intend on working with UTF-8.
Afterwards, remove the MySQL file from C:\xampp\mysql\bin.
Do your trouble shooting in controlled steps:
(1) Does the script looks ok?
DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
type ansi.sql
show databases
(2) Can you connect to your database (even without specified the host)?
DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
(3) Can you source the script? (Hoping for more/better error info)
mysql> source ansi.sql
+--------------------+
| Database |
+--------------------+
| information_schema |
| ... |
| test |
+--------------------+
7 rows in set (0.01 sec)
mysql> quit
Bye
(4) Why does it (still not) work?
DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql < ansi.sql
Enter password: ********
Database
information_schema
...
test
I suspected that the encoding of the script could be the culprit, but I got syntax errors for UTF8 or UTF16 encoded files:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '´╗┐
show databases' at line 1
This could be a version thing; so I think you should make sure of the encoding of your script.
I think the OP's problem was not escaping the slashes.
on windows a path like: "c:\user\folderss\myscript.sql" should in the command line be written like either:
c:\\\user\\\folders\\\myscript.sql
or:
c:/user/folders/myscript.sql
therefore "\u" from "c:\user" was interpreted as a command.
see: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html for more info
here is my try to import database from cmd in xampp server
the correct command for me is this you can change it with your requirements.and i also attached Errors that i face first time importing db from command line.you can see last command that i use and i paste it here also its working fro me.
mysql -h localhost -u root ovxsolut_windhs < C:\Users\eee\Downloads\ovxsolut_windhs.sql
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/filename.sql
mysql -u root -p dbname< "C:\Users\sdkca\Desktop\mydb.sql"
mysql -h localhost -u username -p databasename < dump.sql