首页 > 数据库 >MYSQL BACKUP的SHELL相关语句

MYSQL BACKUP的SHELL相关语句

时间:2022-12-02 11:38:52浏览次数:37  
标签:SHELL database -- Environment DATADIR USER MYSQL BACKUP schema

#!/bin/bash

###############Basic parameters##########################

DAY=`date +%Y%m%d`

Environment=$(/sbin/ifconfig | grep "inet addr" | head -1 |grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}')

USER="backup"

PASSWD="123456"

HostPort="3306"

MYSQLBASE="/home/mysql/"

DATADIR="/home/db_backup/${DAY}"

MYSQL=`/usr/bin/which mysql`

MYSQLDUMP=`/usr/bin/which mysqldump`

mkdir -p ${DATADIR}


Dump(){

${MYSQLDUMP} --master-data=2 --single-transaction --routines --triggers --events -u${USER} -p${PASSWD} -P${HostPort} ${database} > ${DATADIR}/${Environment}-${database}.sql

cd ${DATADIR}

gzip ${Environment}-${database}.sql

}


for db in `echo "SELECT schema_name FROM information_schema.schemata where schema_name not in ('information_schema','sys','performance_schema')" | ${MYSQL} -u${USER} -p${PASSWD} --skip-column-names`

do

database=${db}

Dump

done

标签:SHELL,database,--,Environment,DATADIR,USER,MYSQL,BACKUP,schema
From: https://blog.51cto.com/u_14230175/5906741

相关文章