mysqldump最多隻能把全部數據庫輸出到一個sql中,這樣處理起來有點不方便,找了個shell改了下直接把各個庫的數據分開:mysql
#!/bin/bash USER="username" PASSWORD="password" databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` for db in $databases; do if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then echo "Dumping database: $db" mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`.$db.sql fi done
就是這樣了。sql