分类 默认分类 下的文章
Mysql 使用存储过程和事件实现日志数据表的定期备份功能
我们有时候会把日志数据写入数据库,如果该表不能自动备份,表中的数据会越来越多,影响速度。可以定期将表中数据备份到另外一个表中来解决。
解决方案1
使用MySQL中的存储过程+事件解决。
假设你的日志表名:operationlog
存储过程逻辑为:
1)创建一个新表operationlog_temp,各字段同operationlog相同;
2)将表operationlog更名为operationlog_yyyy-mm-dd;
3)将表operationlog_temp更名为operationlog
事件逻辑为:
1)每个3个月定时调用一次存储过程bakOpLog
注意:开始事件功能(MySQL必须先开启事件功能,才能使用事件)。
查看当前是否已开启事件计划(调度器)有3种方法:
1) SHOW VARIABLES LIKE ‘event_scheduler’;
2) SELECT @@event_scheduler;
3) SHOW PROCESSLIST;
开启事件计划(调度器)开关有4种方法:重启就会销毁
1) SET GLOBAL event_scheduler = 1;
2) SET @@global.event_scheduler = 1;
3) SET GLOBAL event_scheduler = ON;
4) SET @@global.event_scheduler = ON;
1、定义存储过程bakOpLog:
CREATE DEFINER=`sa`@`%` PROCEDURE `bakOpLog`()
BEGIN
create table operationlog_temp like operationlog;
set @i=current_date();
--执行rename table operationlog to operationlog_yyyy-mm-dd
set @sqlstr=CONCAT('rename table operationlog to `operationlog_',cast(@i as char),'`');
select @sqlstr;
PREPARE renameOpLog FROM @sqlstr;
EXECUTE renameOpLog;
rename table operationlog_temp to operationlog;
END;2、定义事件callProcedureBakOpLog
CREATE DEFINER=`sa`@`%` EVENT `callProcedureBakOpLog` ON SCHEDULE EVERY 1 DAY STARTS '2014-12-30 00:00:00' ENDS '2015-01-06 00:00:00' ON COMPLETION PRESERVE ENABLE DO call bakOpLog();3、存储过程用到的一些语法
set @i=current_date(); //将全局变量i赋值为当前日期
set @sqlstr=CONCAT('rename table operationlog to `operationlog_',cast(@i as char),'`'); //sqlstr=rename table operationlog to operationlog_yyyy-mm-dd
PREPARE renameOpLog FROM @sqlstr; //定义预处理语句
EXECUTE renameOpLog; //执行预处理语句查看创建的事件
SHOW EVENTS;也可以在mysql库中产看event表
1) 临时关闭事件
ALTER EVENT e_test DISABLE;2) 开启事件
ALTER EVENT e_test ENABLE;3) 将每天清空test表改为5天清空一次:
ALTER EVENT e_test
ON SCHEDULE EVERY 5 DAY;4) 删除事件(DROP EVENT)
DROP EVENT [IF EXISTS] event_name例如删除前面创建的e_test事件
DROP EVENT e_test;当然前提是这个事件存在,否则会产生ERROR 1513 (HY000): Unknown event错误,因此最好加上IF EXISTS
DROP EVENT IF EXISTS e_test; 一款老牌的文件双向、单向同步软件 unison
一款老牌的文件双向、单向同步软件,可用于自动发布,来现实代码同步到多台服务器
虽然很多年前的软件了,但由于我使用起来还比较顺手,所以记录一下
Unison
当前版本:v2.51.2
项目地址:https://github.com/bcpierce00/unison
官网地址:https://www.cis.upenn.edu/~bcpierce/unison/
ocaml安装
cd /tmp
wget http://caml.inria.fr/pub/distrib/ocaml-3.12/ocaml-3.12.1.tar.gz
tar xzf ocaml-3.12.1.tar.gz
cd ocaml-3.12.1
./configure
make world opt
make installunison安装
cd /tmp
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.40.63.tar.gz
tar xzf unison-2.40.63.tar.gz
cd unison-2.40.63
make UISTYLE=text
mkdir /root/bin
make install
cp /root/bin/unison /usr/bin/unison的使用
英文文档:http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html
中文文章:https://www.centos.bz/2012/02/use-unison-implement-file-two-way-sync/#unison%E7%9A%84%E4%BD%BF%E7%94%A8
微信开发必备
这里收集一些微信开发项目可以使用的一些工具,类库,欢迎推荐!
- PHP 类库:
1、easywechat
基于composer包管理工具开发的微信类库,包含公众号、微信支付、开放平台、企业微信、微信小程序等开发的接口调用,简化调用过程,可以提高开发效率。项目官网 www.easywechat.com
git 出现 refusing to merge unrelated histories 的解决方法
自摘: 林德熙博客 http://blog.csdn.net/lindexi_gd
在合并pull两个不同的项目,会出现的问题: refusing to merge unrelated histories
先pull,因为两个仓库不同,发现refusing to merge unrelated histories
无法pull
因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories
假如我们的源是origin,分支是master,那么我们 需要这样写
git pull origin master --allow-unrelated-histories
需要知道,我们的源可以是本地的路径