数据库
首页 > 数据库> > shell备份mysql的表结构

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导入的时候要忽略错误继续。

标签:shell,备份,DB,echo,USER,mysql,dbname,DIR
来源: https://www.cnblogs.com/toumingbai/p/15763442.html