일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- Italy
- management and leadership
- web
- Kuala Lumpur
- France
- history
- hadoop
- ubuntu
- RFID
- Programming
- program
- Malaysia
- comic agile
- leadership
- management
- Python
- Java
- Linux
- django
- programming_book
- erlang
- agile
- QT
- Book
- MySQL
- UK
- Book review
- Software Engineering
- hbase
- Spain
- Today
- Total
MySQL lock 본문
http://bookworm.pe.kr/wordpress/2013/01/01/2642/
http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html
LOCK IN SHARE MODE
SELECT후 트랜잭션이 끝날 때까지 해당 ROW 값이 변경되지 않음을 보장
즉, 해당 ROW를 UPDATE/DELETE하는 쿼리는 잠김 상태가 되어 트랜잭션이 끝날 때까지 대기 / SELECT는 여러 세션 동시 수행 가능
auto_commit을 꺼야 한다
SELECT * FROM user WHERE id = 1 LOCK IN SHARE MODE;
FOR UPDATE
SELECT로 가져 온 데이터를 변경할 때 사용
해당 ROW에 대해 다른 세션의 SELECT, UPDATE, DELETE등의 쿼리가 모두 잠김 상태
즉, 다른 세션은 모두 해당 ROW에 접근을 할 수 없고, 대기 상태. 트랜잭션이 끝나야 풀림.
SELECT * FROM user WHERE id = 1 FOR UPDATE;
http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql
http://blog.daum.net/hazzling/17187062
https://blog.engineyard.com/2011/5-subtle-ways-youre-using-mysql-as-a-queue-and-why-itll-bite-you
python MySQLdb
http://mysql-python.blogspot.kr
http://mysql-python.sourceforge.net/MySQLdb.html
http://structure.usc.edu/mysqldb/MySQLdb-3.html#ss3.2
try:
connection.begin() # if AUTOCOMMIT is on, use this to temporarily turn it off
cursor.[do somthing]
connection.commit()
except:
connection.rollback()
cf.
http://stackoverflow.com/questions/9136661/set-up-a-mysqldb-connection-object-for-multiple-databases
http://stackoverflow.com/questions/11921366/mysql-and-lock-a-table-read-and-then-truncate
http://stackoverflow.com/questions/6035312/python-mysqldb-multiple-connections