#!/bin/bash user=root password=123456 socket=/var/lib/mysql/mysql.sock mycmd="mysql -u$user -p$password -S $socket" for dbname in oldboy oldgirl vincen;do $mycmd -e "create database $dbname" done
备份数据库
#!/bin/bash DBPATH=/tmp/backup USER=root PASS=123456 SOCK=/var/lib/mysql/mysql.sock DUMP="mysqldump -u$USER -p$PASS -S $SOCK" [ ! -d $DBPATH ] && mkdir -p $DBPATH for dbname in oldboy oldgirl vincen;do $DUMP $dbname | gzip >$DBPATH/${dbname}_$(date +%F).sql.gz done
备份数据表
#!/bin/bash . /etc/init.d/functions BKPATH=/tmp/bakcup USER=root PASS=123456 SOCK=/var/lib/mysql/mysql.sock CMD="mysql -u$USER -p$PASS -S $SOCK" [ ! -d $BKPATH ] && mkdir -p $BKPATH for dbname in oldboy oldgirl vincen;do echo "starting backup $dbname" mkdir $BKPATH/${dbname}_$(date +%F) -p for table in `$CMD -e "show tables from $dbname;"|sed '1d'`;do $CMD $dbname $table|gzip >$BKPATH/${dbname}_$(date +%F)/${dbname}_${table}.sql.gz done action "bakcup $dbname" /bin/true done