mysqldump with db in a separate file

前端 未结 8 1694
生来不讨喜
生来不讨喜 2020-12-02 15:02

I\'m writing a single line command that backups all databases into their respective names instead using of dumping all in one sql.

Eg: db1 get saved to db1.sql and

8条回答
  •  旧时难觅i
    2020-12-02 15:24

    This is what I am using, it's very simple and works fine for me.

    mysql --skip-column-names -u root -p -e 'show databases' | while read dbname; do mysqldump --lock-all-tables -u root -p "$dbname"> "$(date +%Y%m%d)-$dbname".sql; done

    With compression option:

    mysql --skip-column-names -u root -p -e 'show databases' | while read dbname; do mysqldump --lock-all-tables -u root -p "$dbname" | gzip> /tmp/"$(date +%Y%m%d)-$dbname".sql.gz; done

    If you didn't add the password in the command, you need to type it one plus the total number of the databases you have.

提交回复
热议问题