Take the 2-minute tour ×
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. It's 100% free, no registration required.

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 stackoverflow.com Oct 8 '12 at 11:27

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

Also see: stackoverflow.com/questions/105776/… –  Justin Bennett Dec 13 '13 at 14:50

6 Answers 6

use mysqldump -u username -p databasename > filename.sql to export and mysql -u username -p databasename < filename.sql to import

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

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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