Search code examples
mysqldatabaserestoredatabase-backupsmysql-backup

Export and Import all MySQL databases at once


I want to keep a backup of all my MySQL databases. I have more than 100 MySQL databases. I want to export all of them at the same time and again import all of them into my MySQL server at once. How can I do that?


Solution

  • Export:

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

    Look up the documentation for mysqldump. You may want to use some of the options mentioned in comments:

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

    Import:

    mysql -u root -p < alldb.sql