记录-mysql操作-crontab操作

时间:2019-02-15
本文章向大家介绍记录-mysql操作-crontab操作,主要包括记录-mysql操作-crontab操作使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一 mysql基本操作

show databases;
use [数据库名字]

show tables;
参考:https://www.cnblogs.com/dannyyao/p/6533567.html

查看建表语句
show create table t_xifan_user_login;

查看有哪些列
desc t_xifan_user_login;

限制显示行数
select * from t_xifan_user_login limit 10;

显示顺序 order by 默认升序(升序asc,降序desc)
select distinct f_day from t_xifan_user_login order by f_day desc;
select distinct f_act from t_duration_all order by f_act

join操作
https://www.cnblogs.com/fozero/p/6129537.html
以left join为例:
left join是以A表的记录为基础的,A可以看成左表,B可以看成右表,left join是以左表为准的.
换句话说,左表(A)的记录将会全部表示出来,而右表(B)只会显示符合搜索条件的记录(例子中为: A.aID = B.bID).
B表记录不足的地方均为NULL.

in操作
SELECT * FROM Persons
WHERE LastName IN (‘Adams’,‘Carter’)

group by 分组统计数据的时候很方便
SELECT site_id, SUM(access_log.count) AS nums
FROM access_log GROUP BY site_id;
http://www.runoob.com/sql/sql-groupby.html

二 crontab

定时任务
crontab -l 查看已有crontab任务
crontab -e 编写crontab任务

示例一
0 */1 * * * source ~/.bash_profile; cd /home/liubingqi_rd/baidu/hpb-feed-vertical/offline-xifan/xifan_shangyang/xifan_rongzai/; sh run.sh >> /home/liubingqi_rd/baidu/hpb-feed-vertical/offline-xifan/xifan_shangyang/xifan_rongzai/crontab_log/task_log 2>&1

每小时执行一次,
source是用自己的配置,不加此句,可能会导致例如python版本的一些问题,缺少一些库的问题等。
cd切入脚本的目录,sh执行脚本,并把脚本输出输入到指定的文件中,作文log,
2>&1,对于& 1 更准确的说应该是文件描述符 1,而1标识标准输出,stdout。对于2 ,表示标准错误,stderr。2>&1 的意思就是将标准错误重定向到标准输出。

第一位需为0, 如果为* 还是每分钟执行一次,解释如下
https://blog.csdn.net/qq125293177/article/details/80434218

示例二
0 1 * * * source ~/.bash_profile; cd /home/liubingqi_rd/mysql_data/; sh group.sh >> /home/liubingqi_rd/mysql_data/crontab_log/task_log 2>&1

每天 1 点执行该脚本

更多用法:
https://www.jianshu.com/p/d93e2b177814