####
InnoDB B+Tree B+Tree
O(1)
-
-
####
MyISAM MATCH AGAINST WHERE
InnoDB MySQL 5.6.4
#### R-Tree
MyISAM
GIS
### 4.
-
-
-
-
-
- SQL
### 5.
-
-
-
-
-
### 6.
-
-
-
### 7.
>
- MySQL****
key1100select * from table_name where key>1 and key explain select * from user_info where id = 2\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: user_info
partitions: NULL
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 8
ref: const
rows: 1
filtered: 100.00
Extra: NULL
1 row in set, 1 warning (0.00 sec)
```
[MySQL Explain ](https://segmentfault.com/a/1190000008131735)
### 2.
#### 1.
SELECT *
WHERE LIMIT
#### 2.
### 3.
#### 1.
```sql
DELEFT FROM messages WHERE create < DATE_SUB(NOW(), INTERVAL 3 MONTH);
```
```sql
rows_affected = 0
do {
rows_affected = do_query(
"DELETE FROM messages WHERE create < DATE_SUB(NOW(), INTERVAL 3 MONTH) LIMIT 10000")
} while rows_affected > 0
```
#### 2.
JOIN
-
-
-
-
- IN() MySQL ID
```sql
SELECT * FROM tab
JOIN tag_post ON tag_post.tag_id=tag.id
JOIN post ON tag_post.post_id=post.id
WHERE tag.tag='mysql';
SELECT * FROM tag WHERE tag='mysql';
SELECT * FROM tag_post WHERE tag_id=1234;
SELECT * FROM post WHERE post.id IN (123,456,567,9098,8904);
```
## 19.
MySQL/InnoDB
MySQL InnoDB
****
```mysql
select version();
```
****
MySQL MySQL5.6.4
```mysql
SHOW ENGINES
```
### 1.
Version version versionversion1versionversion
****
1
id,value,version
```mysql
select id,value,version from TABLE where id=#{id}
```
2value
```mysql
update TABLE
set value=2,version=version+1
where id=#{id} and version=#{version};
```
### 2.
Java synchronized
************
mysql MySQL autocommit MySQL
MySQL autocommit
```mysql
set autocommit=0;
# autocommit
# 1. ()
begin; / begin work; / start transaction;
# 2.
select status from TABLE where id=1 for update;
# 3.
insert into TABLE (id,value) values (2,2);
# 4.
update TABLE set value=2 where id=1;
# 5.
commit;/commit work;
```
### 3.
****read lock
T A A
```mysql
#
begin; / begin work; / start transaction;
SELECT * from TABLE where id = 1 lock in share mode;
```
id 1
```mysql
update TABLE set name="www.souyunku.com" where id =1;
```
`commit`
```mysql
[SQL]update test_one set name="www.souyunku.com" where id =1;
[Err] 1205 - Lock wait timeout exceeded; try restarting transaction
```
```mysql
update test_one set name="www.souyunku.com" where id =1 lock in share mode;
[SQL]update test_one set name="www.souyunku.com" where id =1 lock in share mode;
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lock in share mode' at line 1
```
`lock in share mode`MySQL
`update,insert,delete`
### 4.
exclusive lock writer lock****
****
1 A X 1 A A A 1 A 1 A A
`for update`
### 5.
********,
****SQL
****
```mysql
#
SELECT * from TABLE where id = "1" lock in share mode;
```
****
```mysql
select status from TABLE where id=1 for update;
```
id id 1
### 6.
innodb ,.
**Innodb**
Innodb
InnoDB InnoDB
InnoDB
SQL
### 7.
Deadlock
****
1.
```mysql
show OPEN TABLES where In_use > 0;
```
2. SUPER
```mysql
show processlist
```
3. idid
```mysql
kill id
```
****
1.
```mysql
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;
```
2.
```mysql
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
```
3.
```mysql
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
```
****
```mysql
kill ID
```
1.
2.
3.
4.
****
1.
2.
3.
4.
5.
- [Mysql - Java - SegmentFault ](https://segmentfault.com/a/1190000015219003#articleHeader0)
- [ - - SegmentFault ](https://segmentfault.com/a/1190000015815061#articleHeader7)
# MySQL
## 1.
2
1
10w
2
### 1
MySQLRedisRedisRedisMySQLDB
DBDBRedis
### 2
**DB**
DB
### 3
**RedisMySQLRedis**DB
DB0
- [ | ](https://mp.weixin.qq.com/s/waGRvyhab2z8b-BIw9bJeA)
- [ - CSDN](https://blog.csdn.net/zhoudaxia/article/details/38067003)
## 2.
1
2
3cache
- [](https://mp.weixin.qq.com/s/5JYtta9aMGcic7o_ejna-A)
#
- [MySQL -](http://www.jikexueyuan.com/course/1524.html)
- [mysql-tutorial/3.5.md at master jaywcjlove/mysql-tutorial](https://github.com/jaywcjlove/mysql-tutorial/blob/master/chapter3/3.5.md)
- [Mysql_ (-) ~-bilibili](https://www.bilibili.com/video/av17252271?from=search&seid=3701018912873961528)
- [](https://tech.meituan.com/dianping_order_db_sharding.html)
- [ | ](https://mp.weixin.qq.com/s/Lfy7ek-vArVBTaUYfl64Bg)
- [](https://www.toutiao.com/a6545626478447428103/?tt_from=weixin&article_category=stock×tamp=1524029012&app=news_article&iid=26214166927&wxshare_count=1)
- [Java-_ (-) ~-bilibili](https://www.bilibili.com/video/av20966672?from=search&seid=6900253656657206494)
- [MySQL_ITPUB](http://blog.itpub.net/29254281/viewspace-1819422/)
-