创建用户:create user 'username' @ 'localhost' identified by 'password'
赋予权限:grant select,update,insert,delete on dbname.tablename(*) to 'user'@'%'
创建db并指定字符集: create database dbname default character set utf8mb4 collate utf8mb4_general_ci
显示数据库字符集:show variables like "char%";
某一行临时指定字符集: set names utf8mb4;
查询
查看表结构:desc tb_name;
查询所有:select * from tb_name;
条件查询:select * from tb_name where a=b;
查询时间段:select * from tb_name where date between '2016-08-01' and '2016-09-01'(左闭右开)
返回数量:
select count(*) from ...
select count(*) from tb_name where job in ('CLERK', 'ANALYST');
select count(*) from tb_name where job is/is not NULL;
select count(*) from tb_name where (a>500 or b="xx") and c like 'J%';
排序:select count(*) from tb_name order by xx, xxx desc
复杂查询(联合): select a.*, p.* from tb_1 as a left join tb_2 as p on a.id = p.user_id order by a.id desc limit 50;