上一章,推荐了个可视化的mysql工具,这章,讲解一些mysql的基本操作。
1 登录mysql:
mysql -h hostname -u user_name -p
输入密码:xxxxx
2 查看一个表的基本操作,去除重复,按字段排序
SELECT distinct spread_name FROM talking_data_records a where a.event_type=1 order by a.spread_name asc;
3 修改表数据的时间
set @dt = now();
update talking_data_records set created_at=date_add(@dt, interval '1 01:15:30' day_second);【增加时间】
update talking_data_records set created_at=date_sub(@dt, interval '1 00:00:30' day_second);【减少时间】
select date_add(@dt, interval -1 day); 【查看减去一天】
4 两表关联查询
select a.x,a.y,a.z,b.* from xxx a,zzz b where a.x=b.y and b.x=1 and
a.created_at >= '2016-11-20 15:59:59' AND a.created_at <= '2016-11-21 15:59:59'