标签:数据库操作
以下这张图是MySQL服务当中经过的一些组件介绍。还是比较详细的,所以此图经常拿来看看也能对MySQL的整个架构加深点印象。
下面来介绍介绍这张图当中的其中一个点 “SQL Interface(数据库接口)- DML”。
通俗的来说,外部要访问内部数据就不得不用此接口的语句来对数据库内的数据进行操作,
语句也分为很多种类,有DDL(数据库定义语句)DML(数据库操作语句)等。操作语句不外乎就是增删查改。分为以下几类:
INSERT
[LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... ]
[LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name SET col_name={expr | DEFAULT}, ... [ ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... ]
[LOW_PRIORITY | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] SELECT ... [ ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... ]
DELETE
Single-table syntax:
[LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [WHERE where_condition] [ORDER BY ...] [LIMIT row_count]
Multiple-table syntax:
[LOW_PRIORITY] [QUICK] [IGNORE] tbl_name[.*] [, tbl_name[.*]] ... FROM table_references [WHERE where_condition]
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name[.*] [, tbl_name[.*]] ... USING table_references [WHERE where_condition]
SELECT
[ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [INTO OUTFILE ‘file_name‘ [CHARACTER SET charset_name] export_options | INTO DUMPFILE ‘file_name‘ | INTO var_name [, var_name]] [FOR UPDATE | LOCK IN SHARE MODE]]
UPDATE
Single-table syntax:
[LOW_PRIORITY] [IGNORE] table_reference SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count]
Multiple-table syntax:
UPDATE [LOW_PRIORITY] [IGNORE] table_references SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition]
语法解释
[LOW_PRIORITY | DELAYED | HIGH_PRIORITY]
存储引擎为MyISAM及MEMORY 则执行优先级 ->读->写->低优先级->高优先级->读->写->
默认为低优先级 - my.cnf配置参数生效 low_priority_updates=1 | 临时参数生效 mysqld --low-priority-updates=1
[IGNORE]
判断是否存在,存在不插入,否则插入
[ON DUPLICATE KEY UPDATE]
根据键或索引来更新字段值
[WHERE where_condition]
条件判断
[GROUP BY]
根据SELECT字段来分组筛选排序
[ORDER BY]
字段筛选排序
[LIMIT]
限定行 | [offset] 行偏移量
[ASC | DESC]
ASC 升序排序 DESC 降序排序
[HAVING]
针对于GROUP BY筛选出的数据进行条件判断
[PROCEDURE]
存储过程
[SQL_CACHE | SQL_NO_CACHE]
是否使用缓存
query_cache_type 这个可以被设置为 (只能是数字) 选项 含义
0 (OFF, 不缓存或重新得到结果)
1 (ON, 缓存所有的结果,除了 SELECT SQL_NO_CACHE ... 查询)
2 (DEMAND, 仅缓存 SELECT SQL_CACHE ... 查询)
SELECT values_to_display
FROM table_name
WHERE expression
GROUP BY how_to_group
HAVING expression
ORDER BY how_to_sort
LIMIT row_count
更多详细内容请参阅官方手册 http://dev.mysql.com/doc/
本文出自 “linux学习” 博客,请务必保留此出处http://antman.blog.51cto.com/8497132/1715130
标签:数据库操作
原文地址:http://antman.blog.51cto.com/8497132/1715130