How to export / import a database in MySQL through the command line?
MySQL system configuration, WampServer server installed.
The advice for my local host, not an live hosting...
Follow the following steps.
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.
mysqldump -u username -p databasename > filename.sql
and to Import:
mysql -u username -p databasename < filename.sql
Go to folder
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
Enter any of the MySQL commands you like with any of the executables you find in that folder.
mysqldump -u db_user -pDB_PASSWORD db_name > /path/to/save/backup_file.sql
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: (http://dev.mysql.com/doc/refman/5.1/en/password-security-user.html):
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
file_nameis the full path name to the file.
To export data in MySQL through msdos is
bin folder of your
mysql directory and search for
mysqldump or put it in environmental variables to access it from anywhere
mysqldump -uroot -p mydb > backup.sql
mysqldump -u <username> -p <password> <databasename> > backup.sql
(provide the username and password and dbname)