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)
Here
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

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...