Exporting Importing MySql database using mysqldump in Linux
Export import is a great feature in almost all databases it provides us the flexibility to move our data from one database to another. Although this can be done through PHPMyadmin as well by simply selecting your database from phpMyAdmin and click on export button.
But exporting and importing database through PhpMyadmin is only good if you have small database . If you have heavy database then it is recommended that you should do it from Linux command prompt (If your server is on Linux). Here are the command for it
Command to export your single database
$ mysqldump -uroot -p db > /var/www/db.sql
Now it will ask for Mysql password. Just enter mysql password (although you can provide it directly from above as well)
root : its your database username
db: Its the name of your database that you want to export.
/var/www/db.sql : Path of your server where you want your exported file .
After running above command you will see a file at your server location.
Command to import your single database
$ mysql -uroot -p db2 < /var/www/db.sql
If you compare this command with the command above you will find above then you will see only a “<” is main different even all parameters are same as above.
Command to export all databases of your mysql server
$ mysqldump -uroot -p --all-databases > /var/www/all-databases.sql
here also parameters will be same as above only the difference is that you don’t need to specify your database name instead of that you need to show –all-database