[TOC]
## 自动备份Mysql数据库
```
#!/bin/bash
#使用方法,位置参数1为需要备份的数据库名,如果固定备份则直接修改参数MysqlDB
Backdir=/data/backup/mysql/`date +%Y-%m-%d`
MysqlDB=$1
MysqlUser=root
MysqlPD=www.upsoft01.com
if [ $UID != "0" ]; then
echo "This script must use root user ,please exit!"
exit 0
fi
if [ -e $1 ]; then
echo "must input database"
exit 0
fi
[ ! -e ${Backdir} ] && mkdir -p ${Backdir}
Mysql_Backup () {
/usr/bin/mysqldump -u${MysqlUser} -p${MysqlPD} ${MysqlDB} | gzip > ${Backdir}/${MysqlDB}-`date +%Y-%m-%d`.sql.gz
}
Mysql_Backup
```
## Mysql复杂操作脚本实例
```
mysql -uroot -pwww.upsoft01.com antdbms_aipu -e 'show tables' | awk '{print $1}'
```