连接
1 | mysql -h <host> -P <port> -u <user> -p <password> |
库
1 | # 查看库 |
表
1 | # 创建表 |
索引
1 | # 删除索引 |
视图
1 | # 查询视图 |
复杂查询
DISTINCT
去除重复记录,默认为 ALL 选项
LIKE
1 | select * from 'table' where field like '%value%' |
UNION & UNION ALL
1 | SELECT column_name(s) FROM table_name1 |
子查询
1 | select a,b,c from a where d IN (select d from b ) |
BETWEEN AND
1 | select * from table1 where time between time1 and time2 |
IN
1 | select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’) |
ORDER BY
语法:
1 | SELECT field1, field2,...fieldN FROM table_name1, table_name2... |
- 你可以使用 ASC 或 DESC 关键字来设置查询结果是按升序或降序排列,默认情况下,按升序排列。
- 你可以添加 WHERE…LIKE 子句来设置条件。
1 | select * from 'tabname' order by field1,field2 [desc] |
统计信息
1 | # 查询数据库总量 |
复制
1 | # 取消复制 |