# 1.安装脚本 #!...$user/mysql/ /usr/local/mysql mv /usr/bin/mysql /usr/bin/mysql.bk$(date '+%Y%m%d%H%M%S') &> /dev/...-u${mysql_user} -p"${mysql_passwd}" -e "${create_db_sql0}" 2>/dev/null mysql -u${mysql_user} -p"...${mysql_passwd}" -e "${create_db_sql1}" 2>/dev/null mysql -u${mysql_user} -p"${mysql_passwd}" -e...-u${mysql_user} -p"${mysql_passwd}" /dev/null echo "--------------------
/mysql/bin/mysql -h${hostip} -P${port} -u${user} -p${passwd} -e "$cmd1"| grep ':' | grep -v 'Variable_name.../mysql/bin/mysql -h${hostip} -P${port} -u${user} -p${passwd} -e "$cmd5"| grep ':' | grep -A1 'log_error..._$(date +%Y_%m_%d).log /home/mysql/mysql/bin/mysql -h${hostip} -P${port} -u${user} -p${passwd} -e "$.../mysql/mysql/bin/mysql -h${hostip} -P${port} -u${user} -p${passwd} -e "$cmd4" | grep -Po '(?...:.*)') Slave_SQL_Running_S=$(/home/mysql/mysql/bin/mysql -h${hostip} -P${port} -u${user} -p${passwd}
常用功能脚本 1.导出整个数据库 mysqldump -u 用户名 -p –default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqldump...数据库控制台,如mysql -u root -p mysql>use 数据库 然后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql>source wcnc_db.sql...p -D dbname < filename.sql 启动与退出 1、进入MySQL: 启动MySQL Command Line Client(MySQL的DOS界面),直接输入安装时的密码即可。...此时的提示符是:mysql> 2、退出MySQL: quit或exit 库操作 1、创建数据库 命令:create database 例如:建立一个名为sqlroad的数据库 mysql>...; 9、导入.sql文件命令 (例如D:/mysql.sql) mysql>use database; mysql>source d:/mysql.sql; 10、删除表 mysql>
/bin/bash # 以下配置信息请自己修改 mysql_user="root" #MySQL备份用户 mysql_password="summer123" #MySQL备份用户的密码 mysql_host...#欢迎语 # 判断MYSQL是否启动,mysql没有启动则备份退出 mysql_ps=`ps -ef |grep mysql |wc -l` mysql_listen=`netstat -an |grep...LISTEN |grep $mysql_port|wc -l` if [ [$mysql_ps == 0] -o [$mysql_listen == 0] ]; then echo "ERROR:MySQL...exit else echo $welcome_msg fi # 连接到mysql数据库,无法连接则备份退出 mysql -h$mysql_host -P$mysql_port -u$mysql_user...`mkdir -p $backup_dir` `/home/summer/mysql/bin/mysqldump -h$mysql_host -P$mysql_port -u$mysql_user -p
/bin/sh #设置用户、密码和主机IP username=用户名 password=密码 hostip=localhost dblists=`/usr/local/mysql/bin.../mysql -u$username -p$password -h$hostip -e"SHOW DATABASES;"` denylists=(Database mysql test information_schema.../bin/mysql -u$username -p$password -h$hostip $dbname -e"SHOW MASTER STATUS;" >>$LogFile #开始备份数据库.../usr/local/mysql/bin/mysqldump -u$username -p$password -h$hostip $dbname -e --max_allowed_packet=10485760...--net_buffer_length=163840 | gzip>$backupdir echo " " >> $LogFile /usr/local/mysql/bin/mysql -u$
案例需求 写一个mysql binlog备份脚本,要求每天0点0分,计算机自动备份前一天的binlog日志,打包后发送给备份服务器。...脚本应用场景: 文件备份 解决问题 日常文件备份 日常数据备份 脚本思路 1、确定binlog的位置及备份时间间隔 每天 当前要备份的binlog是谁 .../bin/bash #Description: #Author: www.zutuanxue.com #Created Time: #将mysql的binlog日志备份到备份服务器 ######...##variables db_user='root' db_password='' log='/var/log/mysql_backup.log' ###main #获得信息 binlog_dir...='/var/lib/mysql' current_binlog=`mysql -u $db_user -e "show master status"|egrep "binlog.
创建一个脚本dbbackup.sh然后内容如下: #!...data date=`date -I`; #取出当前的日期 /opt/lampp/bin/mysqldump -u用户名 -p密码 数据库> 备份文件名前缀_$date.sql; #导出数据库为sql脚本.../bin/tar zcvhf 备份文件名前缀_$date.tar.gz 备份文件名前缀_$date.sql; #压缩sql脚本 rm 备份文件名前缀_$date.sql #删除sql文件 现在我们将这个脚本添加到定时任务中去
环境描述 系统版本: CentOS 7.2 amd64 mysql版本: MySql-5.6.25 脚本依赖: 需要联网 yum 安装 cmake、gcc 等工具。 1....sync_binlog = 1 expire_logs_days = 15 [mysqldump] quick max_allowed_packet = 32M 操作步骤 ---- 1. shell脚本...# 使用脚本完成,mysql 编译、配置、安装步骤。...执行脚本 bash mysql-server.sh # 耐心等待, 笔者2cpu/4GB虚拟机编译时间大约20分钟左右。 3. 启动服务 /etc/init.d/mysqld start 4....验证 mysql mysql -u root -p Enter password: Welcome to the MySQL monitor.
/bin/sh #mysql_backup begintime=`date +"%Y-%m-%d_%H-%M-%S"` format_time=`date +"%Y-%m-%d_%H-%M-%S"` tar_time...=`date +%F --date="-1 day"` currentHour=$(date +%H) port=3306 backdir=/data/backup tardir='/data/mysql_backup...' file_cnf=/etc/my.cnf user_name=root passwd='123456' sock=/data/mysqldata/mysql.sock out_log=$backdir...backdir else #判断昨日是否备份,有则打包压缩后删除之前备份的目录 if [ -d "$backdir/rec2" ];then tar zcf ${tardir}/mysql_bckup
数据同步脚本 1 mysqldump -h[remoteHost] -u[username] -p[password] -P[port] --databases [databasename1] [databasename2...] > DB_MKT_2020-06-29.sql 2 echo "备份完成"; 3 mysql -u[root] -p[123456] -h[localhost] < DB_MKT_2020-06-29...'QRTZ_FIRED_TRIGGERS', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql_bin
1、分库备份 !/bin/bash image.png 2、分库分表备份 !/bin/sh image.png [ ! -d $MYDIR ] && mkd...
1、 !/bin/bash image.png 2、 !/bin/bash image.png 3、 image.png 4、 image.png
/bin/bash #by azura #About database backup #URL https://www.mxsina.com DBCMD=/usr/local/mysql/bin/mysqldump
/bin/sh #mysql_backup begintime=`date +"%Y-%m-%d_%H-%M-%S"` format_time=`date +"%Y-%m-%d_%H-%M-%S"...`date +%F --date="-1 day"` currentHour=$(date +%H) port=3306 backdir=/data/backup tardir='/data/mysql_backup...' file_cnf=/etc/my.cnf user_name=root passwd='123456' sock=/data/mysqldata/mysql.sock out_log=$backdir...backdir else #判断昨日是否备份,有则打包压缩后删除之前备份的目录 if [ -d "$backdir/rec2" ];then tar zcf ${tardir}/mysql_bckup
and /etc/rc0.d/K01mysql.# When this is done the mysql server will be started when the machine is# started...MySQL on some other places than /usr/local/mysql, then you# have to do one of the following things for...=if test -z "$basedir"then basedir=/usr/local/mysql bindir=/usr/local/mysql/bin if test -z "$datadir..." then datadir=/usr/local/mysql/data fi sbindir=/usr/local/mysql/bin libexecdir=/usr/local/mysql...else log_failure_msg "MySQL server process #$mysqld_pid is not running!"
/bin" datadir="/application/mysql/data" mysqld_pid_file_path="/application/mysql/hostname.pid" PATH...@" } Start Func start(){ # Start daemon echo "Starting MySQL" if test -x ?...# 是否处理好返回值是区别脚本是否专业规范的关键。...then echo "Shutting down MySQL" kill $mysqld_pid # 不能带-9,否则后果自负。...fi ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit $return_value #是否处理好返回值是区别脚本是否专业规范的关键
/bin/bash mysql_host="localhost" mysql_user="xxxx" mysql_pwd="xxxxx" #保存备份sql的文件路径 db_dir="/data/backup...-d $db_dir];then # mkdir $db_dir #fi db_arr=$(echo 'show databases' | mysql -u$mysql_user -p$...mysql_pwd -h$mysql_host) #获得当前日期 date=$(date +%Y%m%d) ziname=$date".zip" #指定的数据库文件 thisdb="zzaly"...date".sql" for dbname in ${db_arr} do if [ $thisdb == $dbname ];then mysqldump -u$mysql_user...-p$mysql_pwd -h$mysql_host $dbname > $db_dir"/"$sqlfile fi done find $db_dir -mtime +5 -type f |
今天简单的写了个python的mysql备份脚本,其实也不是很难呀。比shell简洁了很多! 开整: 注释都用英文写了,有些英语基础的朋友应该都可以看得懂了! #!... 'root' #mysqlbackup password Password = 'root' #mysqlbackup command Mysqlcommand = '/usr/local/mysql.../bin/mysqldump' #gzip command Gzipcommand = '/bin/gzip' #backup mysql database Mysqldata = ['gtshop...'sucessful gzip gtshop' else: print 'gzip failed' 执行结果: [root@localhost script]# python mysql_backup.py
本节脚本的使用前提是将mysql(多实例)加入systemctl管理。 1、root登录mysql登录脚本(防止密码泄露) #!...@3306" echo "Status mysql: systemctl status mysqld@3306" mysql -u root -phlaghhioweh -S /home/mysql.../mysql.sock $@ 2、systemctl 管理mysql [Unit] Description=MySQL Percona Server After=network.target After...重构脚本 #!...=/etc/mysql/3306.cnf --user=mysql --datadir=/home/mysql/3306/data echo Start mysqld@3306 systemctl start
mysql批量数据脚本 1 建表 create table dept( id int unsigned primary key auto_increment, deptno mediumint
领取专属 10元无门槛券
手把手带您无忧上云