Git–别名(设置命令的简写)

Git 别名()

$git config 设置命令的别名,达到避免输入完成命令耗费时间
1 $ git config –global alias.co checkout
2 $ git config –global alias.br branch
3 $ git config –global alias.ci commit
4 $ git config –global alias.st status

这意味着,当要输入 git commit 时,只需要输入 git ci。 随着你继续不断地使用 Git,可能也会经常使用其他命令,所以创建别名时不要犹豫。

在创建你认为应该存在的命令时这个技术会很有用。 例如,为了解决取消暂存文件的易用性问题,可以向 Git 中添加你自己的取消暂存$ git config –global alias.unstage ‘reset HEAD –‘下面的两个命令等价:

1 $ git unstage fileA
2 $ git reset HEAD — fileA
这样看起来更清楚一些。 通常也会添加一个 last 命令,像这样:

$ git config –global alias.last ‘log -1 HEAD’
这样,可以轻松地看到最后一次提交:

1 $ git last
commit 66938dae3329c7aebe598c2246a8e6af90d04646
Author: Josh Goebel dreamer3@example.com
Date: Tue Aug 26 19:48:51 2008 +0800

1 test for current head

2

3 Signed-off-by: Scott Chacon <schacon@example.com>
可以看出,Git 只是简单地将别名替换为对应的命令。 然而,你可能想要执行外部命令,而不是一个 Git 子命令。 如果是那样的话,可以在命令前面加入 ! 符号。 如果你自己要写一些与 Git 仓库协作的工具的话,那会很有用。 我们现在演示将 git visual 定义为 gitk 的别名:

$ git config –global alias.visual ‘!gitk’

转自https://blog.csdn.net/MRL6140x/article/details/78211281

Git 生成公钥

生成方法:
1..配置用户名和邮箱
git config –global user.name “用户名,填你的名字全称 如:刘鹏 方便识别”
git config –global user.email “邮箱,填你的常用邮箱,代码出错时会发邮件通知你”
2.生成私钥和公钥
ssh-keygen -t rsa 并按回车3下
(为什么按三下,是因为有提示你是否需要设置密码,
如果设置了每次使用Git都会用到密码,
一般都是直接不写为空,直接回车就好了)
会在一个文件夹里面生成一个私钥 id_rsa和一个公钥id_rsa.pub,
默认文件夹在你打开git bash的目录,或者在你的用户目录~/.ssh文件夹下
3.查看并复制公钥
cat ~/.ssh/id_rsa.pub

mysql 解除数据库访问ip限制

#首先需要关闭防火墙#

systemctl stop firewalld.service            #停止firewall
systemctl disable firewalld.service        #禁止firewall开机启动

— 允许所有远程连接到root权限下的所有数据库

grant all privileges on *.* to root@”%” identified by ‘0’ with grant option;

#  %表示不限制,输入对应的ip地址则解除对应ip地址的访问限制,0表示密码,输入对应的数据访问密码

— 刷新(必要执行的语句)

flush privileges;

创建新用户并给予权限登录数据库

create user ‘gameking’@’%’ identified by ‘root’

grant all on *.* to ‘gameking’@’%’

mysql时间查询语句

MySQL查询的方式很多,下面为您介绍的MySQL查询实现的是查询本周、上周、本月、上个月份的数据,如果您对MySQL查询方面感兴趣的话,不妨一看。

时间日期转换成年月日

from_unixtime(unix_timestamp(createTime),"%Y-%m-%d") as createTime
from_unixtime(time_stamp)   ->  将时间戳转换为日期
unix_timestamp(date)             ->  将指定的日期或者日期字符串转换为时间戳

create_time > UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 3 MONTH)) //近三个月时间选择(时间戳)

查询当前今天的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) =date_format(now(),’%Y-%m-%d’);

查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now());

查询上周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now())-1;

查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(now(),’%Y-%m’)

查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();

查询上个月的数据
select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),’%Y-%m’)

select * from `user` where DATE_FORMAT(pudate,’%Y%m’) = DATE_FORMAT(CURDATE(),’%Y%m’);

select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,’%y-%m-%d’)) = WEEKOFYEAR(now())

select *
from user
where MONTH(FROM_UNIXTIME(pudate,’%y-%m-%d’)) = MONTH(now())

select *
from [user]
where YEAR(FROM_UNIXTIME(pudate,’%y-%m-%d’)) = YEAR(now())
and MONTH(FROM_UNIXTIME(pudate,’%y-%m-%d’)) = MONTH(now())

select *
from [user]
where pudate between 上月最后一天
and 下月第一天

############################

默认情况下, 这个 yearweek、WEEK ( 日期 ) 是 每把周日,作为一周的开始。

有的是周日开始,有的是周一开始。而工作中有的时候每周是从周六开始算的,有些数据需要按周统计,那么那种方式比较好呢?

通过下面的研究,认为yearweek()是适合的,它返回的是 201311这样的格式。若要把周六当做新的一周的开始,那么就是:

select yearweek(DATE_ADD(now(), INTERVAL 1 DAY));

mysql> select yearweek(DATE_ADD(now(), INTERVAL 1 DAY));
+——————————————-+
| yearweek(DATE_ADD(now(), INTERVAL 1 DAY)) |
+——————————————-+
| 201311 |
+——————————————-+
1 row in set

mysql> select yearweek(now());
+—————–+
| yearweek(now()) |
+—————–+
| 201310 |
+—————–+
1 row in set

mysql>

select yearweek(now() – INTERVAL 1 DAY) 从周1开始本周计算

select yearweek(‘2015-02-02 11:12:00’ – INTERVAL 1 DAY)

############################

摘自:http://hideto.javaeye.com/blog/255816

当前week的第一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 1 DAY)

当前week的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) – 5 DAY)

前一week的第一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 8 DAY)

前一week的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 2 DAY)

前两week的第一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 15 DAY)

前两week的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 9 DAY)
当前month的第一天:
SELECT concat(date_format(LAST_DAY(now()),’%Y-%m-’),’01′)

当前month的最后一天:
SELECT LAST_DAY(now())

前一month的第一天:
SELECT concat(date_format(LAST_DAY(now() – interval 1 month),’%Y-%m-’),’01′)

前一month的最后一天:
SELECT LAST_DAY(now() – interval 1 month)

前两month的第一天:
SELECT concat(date_format(LAST_DAY(now() – interval 2 month),’%Y-%m-’),’01′)

前两month的最后一天:
SELECT LAST_DAY(now() – interval 2 month)
当前quarter的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),’%Y-%m-’),’01′)

当前quarter的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month)

前一quarter的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-6 month),’%Y-%m-’),’01′)

前一quarter的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-4 month)

前两quarter的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-9 month),’%Y-%m-’),’01′)

前两quarter的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-7 month)

UNIX时间戳转换为日期用函数: FROM_UNIXTIME()

select FROM_UNIXTIME(1156219870);
日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP()

Select UNIX_TIMESTAMP(’2006-11-04 12:23:00′);

########################

今天

select * from 表名 where to_days(时间字段名) = to_days(now());

昨天

SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) – TO_DAYS( 时间字段名) <= 1 7天 SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名) 近30天 SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名) 本月 SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, ‘%Y%m’ ) = DATE_FORMAT( CURDATE( ) , ‘%Y%m’ ) 上一月 SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , ‘%Y%m’ ) , date_format( 时间字段名, ‘%Y%m’ ) ) =1 #查询本季度数据 select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now()); #查询上季度数据 select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER)); #查询本年数据 select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW()); #查询上年数据 select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year)); 查询当前这周的数据 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now()); 查询上周的数据 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now())-1;//国外一周是从周日到周六来算的 SELECT * FROM ordersrecord WHERE YEARWEEK(ordertime,1) =YEARWEEK(date_sub(curdate(),interval 7 day),1) 查询当前月份的数据 select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(now(),’%Y-%m’) 查询距离当前现在6个月的数据 select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now(); 查询上个月的数据 select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),’%Y-%m’) select * from ` user ` where DATE_FORMAT(pudate, ‘ %Y%m ‘ ) = DATE_FORMAT(CURDATE(), ‘ %Y%m ‘ ) ; select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,’%y-%m-%d’)) = WEEKOFYEAR(now()) select * from user where MONTH (FROM_UNIXTIME(pudate, ‘ %y-%m-%d ‘ )) = MONTH (now()) select * from [ user ] where YEAR (FROM_UNIXTIME(pudate, ‘ %y-%m-%d ‘ )) = YEAR (now()) and MONTH (FROM_UNIXTIME(pudate, ‘ %y-%m-%d ‘ )) = MONTH (now()) select * from [ user ] where pudate between 上月最后一天 and 下月第一天 where date(regdate) = curdate(); select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now()) SELECT date( c_instime ) ,curdate( ) FROM `t_score` WHERE 1 LIMIT 0 , 30 摘自:http://blog.csdn.net/zzhongcy/article/details/43016685