MySQL使用MySQLdump导出所有库
导出所有数据库
/usr/local/mysql/bin/mysqldump -u用户名 -p密码 --lock-all-tables --all-databases > /tmp/all.sql
导入数据库
/usr/local/mysql/bin/mysqldu -u用户名 -p密码 < /tmp/all.sql
导出指定库,排除不导出的库
#!/bin/bash
USER="用户名"
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
备份所有用户名密码
mysql -BNe "select concat('\'',user,'\'@\'',host,'\'') from mysql.user where user != 'root'" | \
while read uh; do mysql -BNe "show grants for $uh" | sed 's/$/;/; s/\\\\/\\/g'; done > grants.sql
Tag标签:「导出 备份 mysqldump」更新时间:「2021-11-03 22:57:18」阅读次数:「783」