Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to export / import a database in MySQL through the command line?

MySQL system configuration, WampServer server installed.

OS: Windows

The advice for my local host, not an live hosting...

share|improve this question

migrated from Oct 8 '12 at 11:27

This question came from our site for professional and enthusiast programmers.

Also see:… – Justin Bennett Dec 13 '13 at 14:50

Use this for export:

mysqldump -u username -p databasename > filename.sql

Use this for import:

mysql -u username -p databasename < filename.sql
share|improve this answer
This is the first time am doing the export using sql, Tell my my sql can place any where , that is my file may in desktop or d drive , or is there any particular location i have past my sql file – Bharanikumar Apr 25 '10 at 12:04
you can place your file anywhere as long as you have your mysql bin folder in your PATH. the alternative is to call the mysql and mysqldump executables using the full path to them (e.g F:\wamp\bin\mysql\mysql5.1.36\bin\mysql and F:\wamp\bin\mysql\mysql5.1.36\bin\mysqldump) . In your screenshot the problem is that you didn't supply the username and password when starting the mysql program (you supply it with: mysql -u USERNAME -p <enter> and then type your password) – matei Apr 26 '10 at 5:47

To backup:

mysqldump -u user -p database > backup.sql

To import:

mysql -u user -p database < backup.sql
share|improve this answer
mysql> mysqldump -u root -p sale > backup.sql -> ; ERROR 1064 (42000): 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 'mysql dump -u root -p sale > backup.sql' at line 1 – Bharanikumar Jan 23 '13 at 9:14
@Bharanikumar I don't think you didn't find out, but you need to use the mysqldump.exe not the mysql.exe. – appl3r Aug 12 '15 at 6:23

Follow the following steps.

  1. Run cmd command
  2. Type c: or d: on command prompt. This will be based on your WAMP server installations.
  3. Assuming you have installed wamp on C: drive.
  4. C:>cd wamp
  5. C:\wamp>cd bin
  6. C:\wamp\bin>cd mysql
  7. C:\wamp\bin\mysql>cd mysql15.5.8
  8. C:\wamp\bin\mysql\mysql15.5.8>cd bin
  9. C:\wamp\bin\mysql\mysql15.5.8\bin>mysql.exe -u root

Now you'll get mysql command prompt.

** Note Here My MySql version ins 15.5.8 it may change based on your wamp installation. Now you can follow the answer by @Matei. I'm pasting his answer here. Hope this will help you.

use mysqldump -u username -p databasename > filename.sql to export and mysql -u username -p databasename < filename.sql to import
share|improve this answer

Go to folder C:\wamp\bin\mysql\MYSQL_VERSION\bin

Hit shift + right-click in that folder and select "Open command window here" from the menu that pops up.

This will open a command window in the path you are already in, so C:\wamp\bin\mysql\MYSQL_VERSION\bin

Enter any of the MySQL commands you like with any of the executables you find in that folder.

To export:

mysqldump -u db_user -pDB_PASSWORD db_name > /path/to/save/backup_file.sql

To import:

mysql -u db_user -p db_name < /path/to/save/backup_file.sql

The user has a password (DB_PASSWORD) and that needs to be directly behind -p without a space. Beware like this the password can be seen by other programs.

If you do not specify a password in the command directly after the -p flag and just use the db_name you will be asked to put in the password interactively every time you run the command.

This means every time you want to export or import your databse you have to put in the password. This is also not very secure and like this you cannot run a script to automatically export your database at a given time interval.

So it is best to follow this advice:

Quoting the MySQL documentation: (

Store your password in an option file. For example, on Unix you can list your password in the [client] section of the .my.cnf file in your home directory:


To keep the password safe, the file should not be accessible to anyone but yourself. To ensure this, set the file access mode to 400 or 600. For example:

shell> chmod 600 .my.cnf

To name from the command line a specific option file containing the password, use the --defaults-file=file_name option, where file_name is the full path name to the file.

share|improve this answer

To export data in mysql through msdos is Goto->the bin folder of your mysql directory and search for mysqldump or put it in environmental variables to access it from anywhere 1.if user is root with no password mysqldump -uroot -p mydb > backup.sql 2.if username and password mysqldump -u -p > backup.sqp (provide the username and password and dbname)

share|improve this answer

mysql -u user -p database < backup.sql

share|improve this answer

Install HeidiSQl it Easy way to Export Mysql File. Also it is SQL Editor

share|improve this answer

If you want to export all databases, use this:

set path=c:/wamp/bin/mysql/mysql5.5.24/bin/
mysqldump -u root -ppassword --all-databases > /exported_dbs.sql` 

It worked for me in windows.

share|improve this answer

protected by Community Jan 15 at 9:53

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.