当前位置:Gxlcms > 数据库问题 > 备份mysql数据库

备份mysql数据库

时间:2021-07-01 10:21:17 帮助过:16人阅读

date +%Y-%m-%d

yum install -y mysql-server

rpm -qf /usr/bin/mysql

 

mysql

show databases;

mysql -uroot -p

 

 

#!/bin/sh
#auto backup mysql
BAKDIR=/data/backup/mysql/`date +%Y-%m-%d`
MYSQLUSR=root
if
        [ $UID -ne 0 ];then
        echo This script must be use the root user!!!
        sleep 2
        exit 0
fi

if [ ! -d $BAKDIR ];then
        mkdir -p $BAKDIR
else
        echo This is $BAKDIR exists...
fi
/usr/bin/mysqldump -u$MYSQLUSR -d $MYSQLDB >$BAKDIR/webapp_db.sql
cd $BAKDIR;tar -czvf webapp_mysql_db.tar.gz *.sql
#find . -type f -name *.sql|xargs rm -rf
find . -type f -name *.sql -exec rm -rf {} \;
[ $? -eq 0 ]&&echo "This `date +%Y-%m-%d` MYSQL BACKUP IS SUCCESS"
cd /data/backup/mysql/; find . -type d -mtime +30|xargs rm -rf
echo "This mysql backup successfully"

备份mysql数据库

标签:amp   tab   exist   rgs   备份   -name   sql数据库   数据库   base   

人气教程排行