1.权限更改时,给有相应页面权限且没有14平台权限的人,加上14平台权限
update `user` set `group`=CONCAT(`group`,',14')
WHERE power LIKE '%4017%' and `group` NOT LIKE '%14%'
2.多表联合修改
UPDATE A a,B b
SET b.LTV=a.LoginCnt
where a.Log_Date='2016-3-11' and b.Log_Date=a.Log_Date and b.Channel_ID=a.Channel_ID and b.Server_ID=a.Server_ID
3.查看表的创建信息
SHOW CREATE TABLE A
4.选择上一周的周日
select convert(subdate(curdate(),date_format(curdate(),'%w')+7),char(10))
本周周日加0
select convert(subdate(curdate(),date_format(curdate(),'%w')+0),char(10))
5.选择每10秒的数据
select *,convert(concat(CONVERT(log_time,char(18)),'0'),datetime)
from log_online
WHERE log_time BETWEEN '2016-6-4' AND '2016-6-5'
order by 1
6. 导出数据的表
mysqldump -h 10.10.39.170 -uroot -p xxx dim_action > dim_action.sql
7. 查看数据库中表的数量
SELECT count( * ) FROM information_schema.tables WHERE TABLE_SCHEMA = 'XXX';
8. 查看数据库中存储过程的数量
select count(*) from mysql.proc where db = 'XXXX' and `type` = 'PROCEDURE';
9. 查看数据库中存储过程的名称
select `name` from mysql.proc where db = 'XXX' and `type` = 'PROCEDURE';
10. 添加单个多列索引,优化查询速度
ALTER TABLE report_daily_keep ADD INDEX Log_Date(Log_Date,Channel_ID,Server_ID)
alert table 表名 add index 索引名(列名1,列名2,列名3...)
11.删除索引
ALTER TABLE XXX DROP INDEX Log_Date
alert table 表名 drop index 索引名
12. mysql 查询的结果插入到另外的表
INSERT into user_logout_identify_copy(username,is_logout)
SELECT `name`,1 from `user`
13. 先求出两个表格的差集,然后把差集插入到另一个表中
INSERT into A_column(column_name, translate_name)
( SELECT * from B_column WHERE column_name not in ( SELECT column_name from A_column) )
不断更新中….