MySQL??????????
???????????? ???????[ 2017/1/17 10:31:20 ] ????????????? MySQL
?????????????????MySQL??????????????ó??????м???????
???????:???? BDB??
???????:???? MyISAM ?? ????????????????????????д????
?????м?:???? INNODB ?? ????????м??????
???????????????????????????????????????????????????д?????????????д????????????????????????
?????м???????????????????м???????????????????????????????е???????????в?????
??????????????????????????м????????????????????????????????????????????????????
????MySQL 5.1????MyISAM??MEMORY????б??????????BDB????????????????InnoDB??????м???????
??????WRITE??MySQL???????????????????£?
???????????????????????????????д????
?????????????????????д?????????С?
??????READ??MySQL??????????????????£?
???????????????д???????????????????????????
?????????????????????????????С?
????InnoDB???????????BDB????????????????????洢???棬??????????????????????????SQL????????InnoDB??????????????BDB????????????????????????????á?
?????м??????????
????· ???????????з????????????????????????????
????· ?????????????????
????· ??????????????????С?
?????м??????????
????· ??????????????????????檔
????· ????????????????????????????????????????????????????????
????· ???????????????????????GROUP BY??????????????????????????????????????????
????· ??????????????????????????????????????????????????ó?????????????С???м???????
??????????????£???????????????????м???????
????· ?????????????????
????· ????????????ж??????£????????????????????????????????????????У?
????· UPDATE tbl_name SET column=value WHERE unique_key_col=key_value;
????· DELETE FROM tbl_name WHERE unique_key_col=key_value;
????· SELECT ?????е?INSERT?????????к????UPDATE??DELETE???
????· ???????????????????GROUP BY??????????κ?д??????
????/* ========================= mysql ??????????????? ========================= */
??????????????????????????? INSERT ?? SELECT ????????????е????????????????????????????????У?????????????е???????μ??????????????????????????
??????????????????:
????mysql> LOCK TABLES real_table WRITE?? insert_table WRITE;
????mysql> INSERT INTO real_table SELECT * FROM insert_table;
????mysql> TRUNCATE TABLE insert_table;
????mysql> UNLOCK TABLES;
?????м?????????У?
??????????????????????????????
??????????????????????
??????????????????м??????????????
?????м?????????У?
???????????????????????????檔
????????????Э??????????????????????????????????????????????????С??????????????????????????????????????????α??????????????????????Ч?????????????????????????????????????????????????????????????????????????????????????????Ч??????????????????????????????????????????????????????????
????MySQL??????????????????????????????洢??????????????????
???????磬MyISAM??MEMORY?洢????????????????table-level-locking????BDB?洢?????????????????page-level-locking????????????????InnoDB?洢?????????м?????????????????????????????м?????
???????????????????????1??????£?
????1?? ???????????С??????????????????????????????????????????????????????
????2?? ?м??????????????????????????????????????С????????????????????????????
????3?? ?????????????????????????????????????????????????????????????????????????????
?????????????и???????????????????????????????????????????????????????????????????????????WEB?????м???????????д??????????????????????????????????????в???????????????Щ???????????OLTP??????
????MySQL?????????????????????????Table Read Lock???????д????Table Write Lock?????????????????MyISAM????ж????????????????????????????????????????????? ???????д??????????MyISAM???д??????????????????????????????д??????
????MyISAM??????д????е????????ж?????????????д??????????????????????????????MyISAM?????????????????????????У??????????????????????????concurrent_insert???????е????????????0??????????????????????????1 ??????MyISAM??????п????????????б???????У???MyISAM????????????????????????????????β??????????????????2???????MyISAM????????п?????????????β????????????
????MyISAM???????????????????????????????????????磬????????????????MyISAM?????????????????????????????д???????MySQL???????????????????????о???????д?????????????????????????????????У??????????????????????????????д????????????????????????????????????????????????????????????Щ??????????MyISAM?????????????????????????low-priority-updates???MyISAM???????????????????????????????????1??set low_priority_updates=1)?????????????
????InnoDB????MyISAM?????????????????????TRANCSACTION??????????????м???????????????????????SQL?????????????????????????????????ACID?????????????
??????????Atomicity???????????????????????????????????????????У??????????У?
??????????Consistent?????????????????????????????????????
???????????Isolation???????????????????????????????????????????????????“????”??????У?
??????????Durable????????????????????????????????????????????????????????
????InnoDB????????????????
????1??????????????????????????У????????????????????????????????
????( Select * from table_name where ......lock in share mode)
????2???????????????????????????????????????????????????????????????????? ????д????(select * from table_name where.....for update)
???????????????????????棬?????????????????????????????????????????????????????????????????????????????
????InnoDB????????????????????????????????????????????????????InnoDB??????м?????????????????
???????????????????????????????????
??????????????????:
????bulk_insert_buffer_size
???????????????С?? ????????????MyISAM?洢?????????.????????????????100-1000+???????? ???Ч??.??????8M.????????????????С??????????.
????concurrent_insert
???????????? ??????п??(????????)?? ???????????????????£???????????????β?????в???.
???????????0????????????? 1??????п????? ??в??????? 2????????п??????в???????.
?????????1 ?????????????????.
????delay_key_write
???????MyISAM?洢???棬??????????.????????update?????????????up???????????up?????????????????????????????????????????д??????. ?? 0??????? 1????. ??????.
????delayed_insert_limit?? delayed_insert_timeout?? delayed_queue_size
?????????? ????????????????У? ????????????.??????Щ????????????е?洢???涼???? ???????? ?????InnoDB?????? MyISAM???. ?????????????? ???????????
????/* ==================== MySQL InnoDB ?????????? ======================== */
????????InnoDB?????Row-Level Lock????????С?????????????????MySQL??????Row lock (????????????????) ??????MySQL???????Table Lock (?????????????????)??
???????????: ?????и????products ????????id??name??????λ??id????????
??????1: (?????????????????д???????row lock)
??????????????????:
????SELECT * FROM products WHERE id='3' FOR UPDATE;
????SELECT * FROM products WHERE id='3' and type=1 FOR UPDATE;
??????2: (??????????????????????????lock)
??????????????????:
????SELECT * FROM products WHERE id='-1' FOR UPDATE;
??????3: (????????table lock)
??????????????????:
????SELECT * FROM products WHERE name='Mouse' FOR UPDATE;
??????4: (???????????table lock)
??????????????????:
????SELECT * FROM products WHERE id<>'3' FOR UPDATE;
??????5: (???????????table lock)
??????????????????:
????SELECT * FROM products WHERE id LIKE '3' FOR UPDATE;
?????1: FOR UPDATE????????InnoDB????????????????(BEGIN/COMMIT)?в?????Ч??
?????2: ????????????????????????MySQL??Command Mode ????????????????????
??????MySql 5.0?в?????????????
????????MyAsim ??????????InnerDB????м???
?????????(?м???/?????)??????????????????????????????????????????????????????
???????????????????????????????????????
???????????A??B?????id???в??????????????????A??B????????????row??????A??B?????????????????A????????????????????B????????????????У????B???????????????????????Deadlock found when trying to get lock; try restarting transaction?????????????A???????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11