1. shell脚本-导出mysql数据
#! /bin/bash
#数据库信息
mysql_user='root'
# mysql密码
mysql_password=""
# mysql的IP
mysql_host=""
# mysql 端口
mysql_port="6306"
# 数据存放路径
backup_dir="/home/data1/taishi/app/mysqlback"
# 库名
database_name="portal"
# 时间
dt=$(date +"%Y%m%d%H")
# 备份全部数据库
#mysqldump -h $mysql_host -P$mysql_port -u$mysql_user -p$mysql_password portal --single-transaction > $backup_dir/mysql_backup_$dt.sql
# 导出指定的表 portal.portal_ability_indicators portal.sa_type_def
#mysqldump -t portal -h $mysql_host -P$mysql_port -u$mysql_user -p$mysql_password --tables portal_ability_indicators sa_type_def >$backup_dir/mysql_backup_$dt.sql
# 除了某些表(portal.ops_test,portal.portal_ability_indicators)之外,其余的都导出
#mysqldump -h $mysql_host -P$mysql_port -u$mysql_user -p$mysql_password --default-character-set=utf8 portal --ignore-table=portal.ops_test --ignore-table=portal.portal_ability_indicators >$backup_dir/mysql_backup_$dt.sql
# 只导出表结构
mysqldump -d portal -h $mysql_host -P$mysql_port -u$mysql_user -p$mysql_password --tables portal_ability_indicators ops_test > $backup_dir/mysql_backup_$dt.sql
# 删除7天之前的文件
#find $backup_dir -mtime +7 -type f -name '*.sql' -exec rm -rf {} \;
echo "Backup Succeed Date:" $(date +"%Y-%m-%d %H:%M:%S")
2. shell脚本登入mysql 数据
导入SQL文件
source /home/data1/taishi/app/mysqlback/test.sql