shell备份mysql的表结构

#!/bin/bash
DB_USER="root"
DB_PASS="密码"
DB_NAME="MYSQL1"
BIN_DIR="/usr/bin"
BACK_DIR="./"
MYSQL_IP="127.0.0.1"
for dbname in $(mysql -u$DB_USER -p$DB_PASS -h $MYSQL_IP -P 3306 -e "show databases;" | grep -Evi "binlog|logs|performance_schema|information_schema|perfo|database|mysql")
do
echo $dbname;
echo "use ${dbname};">>结构文件.sql
$BIN_DIR/mysqldump --single-transaction -h $MYSQL_IP -P 3306 -u$DB_USER -p$DB_PASS -d $dbname >>结构文件.sql
done
echo "$DB_NAME done"

这样备份出来的文件换行符要转换成windows下的,然后navicat导入的时候要忽略错误继续。

posted @ 2022-01-04 17:52  鱼肉真好吃  阅读(144)  评论(0编辑  收藏  举报