快速登录任意mysql脚本
#####################
#!/bin/bash # 获取输入参数 ip="" port="" database="" query="" password_BASE64='WldFeU1HTXhaVFkxWWpnMk56WTFNVFUyTkRObE5qazQK' while [ $# -gt 0 ] do case $1 in -h) ip=$2 shift ;; -P) port=$2 shift ;; *) if [[ -z "$ip" ]]; then if [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then ip=$1 else if ping -c 1 $1 &>/dev/null; then ip=$1 else database=$1 fi fi elif [[ -z "$port" ]]; then if [[ "$1" =~ ^[0-9]+$ ]]; then port=$1 else database=$1 fi elif [[ -z "$database" ]]; then database=$1 else query="$query $1" fi ;; esac shift done # 确认默认值 if [[ -z "$ip" ]]; then ip="127.0.0.1" fi if [[ -z "$port" ]]; then port="3306" fi # 构造mysql命令 dbpass=$(echo "WldFeU1HTXhaVFkxWWpnMk56WTFNVFUyTkRObE5qazQK"|base64 -d) mysql_command="mysql -udba -p$dbpass -h $ip -P $port $database $query" # 执行mysql命令 echo "==================================" echo "$mysql_command"|sed 's/-p.*k4/-pxxx/g' echo "==================================" eval $mysql_command
快速物理备份并压缩
#!/bin/bash mysql_port="3308" host_name=$(hostname) # 设置保留的备份数量 retain_days=5 # 定义备份目录 backup_dir="/data/backup/mysql_backup/${host_name}_${mysql_port}" mkdir -p $backup_dir # 定义备份文件名 backup_file="mysql_backup_$(date +%Y%m%d%H%M%S).tar.gz" # 使用innobackupex进行全量备份,并将备份文件压缩为.tar.gz格式 /data/glc/soft/percona-xtrabackup-2.4.27-Linux-x86_64.glibc2.12/bin/innobackupex --defaults-file=/data/glc/mysql_3306/conf/my.cnf --login-path=backup_3306 --no-timestamp --slave-info --stream=xbstream ${backup_dir} |gzip > ${backup_dir}/${backup_file} # 删除旧的备份文件,只保留最近5天的备份文件 find $backup_dir -maxdepth 1 -name "mysql_backup_*" -type f -mtime +$retain_days -delete
快速生成32位密码:
[root@xxx scripts]# cat password_new.sh #!/bin/bash username=$1 user_password=$(date +%s |sha256sum|base64|head -c 32) new_time=$(date '+%Y%m%d%H%M%S') mysql_user='root' mysql_passwd='root' mysql_port=3306 mysql_host=='' echo "username: $username" echo "password: $user_password" echo "time: $new_time" >> log.password_new echo "username: $username" >>log.password_new echo "password: $user_password" >>log.password_new
##########################
igoodful@qq.com