mysql,

How to export and import all MySQL databases at once

Nov 12, 2021 · 1 min read · Post a comment

Working with microservices will ramp up the number of MySQL databases. So, if you need to create a backup for all of them at once there is a way to do it through the CLI. Also importing them at once is achievable as well.

Prerequisites

  • MySQL database
  • MySQL root access

Export

Step 1. To export all MySQL databases at once, run:

mysqldump -u root -p --all-databases > backupalldbs.sql

Step 2. If there are some lock tables you may face issues. So to skip them, run:

mysqldump -u root -p --all-databases --skip-lock-tables > backupalldbs.sql

Import

If you need to import all the databases at once, run:

mysql -u root -p < backupalldbs.sql

Conclusion

If you have some specific requirements while backing up your MySQL databases don’t hesitate to raise a question in the comments below. If you find this tutorial useful, follow our official channel on Telegram.