mysql ¹²ÏíËø ÅÅËûËø ·À²åÈëËø
ÊÔÑé1
ÊÂÎñ1£º
#!/usr/bin/python
import time
import MySQLdb;
conn = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="asdf",db="test",unix_socket="/data/mysql_3306/mysql.sock")
cursor = conn.cursor()
cursor.execute("select * from test")
while str!="1":
str = raw_input()
cursor.execute("update test id=id-1")
while str!="exit":
str = raw_input()
cursor.close()
conn.close()
ÔÚmysqlÃüÁîÐÐÖÐÊäÈëÒÔÏ£º
mysql> select * from test;
µ±ÊÂÎñ1ÖеȴýÊäÈë1ʱ£¬ÏÔʾ³öselectÆ¥ÅäµÄÐÐ
µ±ÊÂÎñ1ÖÐÊäÈë1ʱ£¬ÏÔʾ½á¹ûÈçÏ£º
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
½áÂÛ£ºµ±selectʱ»á¼ì²âµ±Ç°ÊÇ·ñÓÐÊÂÎñ»áÐ޸썱ÈÓ°ÏìҪȷÇÐһЩ£©µ±Ç°µÄ¼Ç¼ʱ£¬²Å»á±»×èÈû¡£
ÊÔÑé2
ÔÚÊÂÎñ1£º
#!/usr/bin/python
import time
import MySQLdb;
conn = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="asdf",db="test",unix_socket="/data/mysql_3306/mysql.sock")
cursor = conn.cursor()
cursor.execute("select * from test lock in share mode")
while str!="exit":
str = raw_input()
cursor.close()
conn.close()
ÔÚmysqlÃüÁîÐÐÖÐÊäÈëÒÔÏ£º
mysql> update test set id=id-1;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
½áÂÛ£ºµ±ÊÂÎñÖаüº¬select ...lock in share modeµÄʱºò£¬Ïà¹Ø¼Ç¼½«»á±»Ëø×¡£¬²»ÔÊÐí½øÐÐÐ޸ġ£
ÊÔÑé3
Ö´ÐÐÏÂÃæµÄpython½Å±¾Á½±é£¬²¢ÇÒͬʱÊäÈë1£¬2Ö®ºó
#!/usr/bin/python
import time
import MySQLdb;
conn = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="asdf",db="test",unix_socket="/data/mysql_3306/mysql.sock")
cursor = conn.cursor()
cursor.execute("select * from test lock in share mode")
str = ""
while str!="1":
str = raw_input()
while str!="2":
str = raw_input()
cursor.execute("update test set id=id-1")
while str!="exit":
str = raw_input()
cursor.close()
conn.close()
[root@TJSJHL196-139 tmp]# python test_transaction.py
1
2
Traceback (most recent call la
Ïà¹ØÎĵµ£º
ÊýÖµÀàÐÍ
¡¡¡¡MySQL µÄÊýÖµÊý¾ÝÀàÐÍ¿ÉÒÔ´óÖ»®·ÖΪÁ½¸öÀà±ð£¬Ò»¸öÊÇÕûÊý£¬ÁíÒ»¸öÊǸ¡µãÊý»òСÊý¡£Ðí¶à²»Í¬µÄ×ÓÀàÐͶÔÕâЩÀà±ðÖеÄÿһ¸ö¶¼ÊÇ¿ÉÓõģ¬Ã¿¸ö×ÓÀàÐÍÖ§³Ö²»Í¬´óСµÄÊý¾Ý£¬²¢ÇÒ MySQL ÔÊÐíÎÒÃÇÖ¸¶¨ÊýÖµ×Ö¶ÎÖеÄÖµÊÇ·ñÓÐÕý¸ºÖ®·Ö»òÕßÓÃÁãÌî²¹¡£
¡¡¡¡±íÁгöÁ˸÷ÖÖÊýÖµÀàÐÍÒÔ¼°ËüÃǵÄÔÊÐí·¶Î§ºÍÕ¼ÓõÄÄÚ´æ¿Õ¼ä¡£
......
¹ØÓÚMYSQLµÄshow status½âÏê
SHOW STATUSÌṩ·þÎñÆ÷µÄ״̬ÐÅÏ¢(Ïómysqladmin extended-statusÒ»Ñù)¡£Êä³öÀàËÆÓÚÏÂÃæµÄÏÔʾ£¬¾¡¹Ü¸ñʽºÍÊý×Ö¿ÉÒÔÓе㲻ͬ£º
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| Aborted_clients | 0 |
| Aborted_connect ......
ÔÚ¿ª·¢ÏîĿʱ£¬Óöµ½Ò»¸öÎÊÌ⣬¾ÍÊÇÒªËæ»ú¶ÁȡһÕűíµÄ²¿·Ö¼Ç¼£¬²¢updateÉèÖÃΪ²»¿ÉÔÚ¶Á£¬ÕâÀï¾ÍÓÐÒ»¸öÎÊÌ⣬¿ÉÄܶà¸öÈËÍ¬Ê±Ëæ»úµ½ÏàͬµÄ¼Ç¼£¬²¢Öظ´×öupdate²Ù×÷£¬ÒýÆðÊý¾ÝÔà¶ÁºÍÖØ¸´²Ù×÷£¬
Òò´Ë¿¼ÂǸø±í¼ÓËø¡£µ«ÊDzÉÓÃÁËMyISAM£¬²»Ö§³ÖÊÂÎñ£¬Ö»ÄÜ¼Ó±í¼¶Ëø£¬¶øÇÒ±ðÈËÁ¬¶ÁµÄȨÏÞ¶¼Ã»ÓС£ÏÂÃæÊÇ2¸ö²âÊÔÎļþ£¬ÔÚfiref ......
1.¼ì²éÒÔǰ°²×°µÄMySQL,Ð¶ÔØ¡£
rpm -qa|grep -i mysql
rpm -e XXXXX
×¢Èç¹û³öÏÖÁ½ÌõÏàͬµÄ£¬ÔòʹÓÃrpm -e --allmatches
2.°²×°rpm°ü¡£
rpm -ivh MySQL-server-community-5.1.37-0.rhel5.x86_64.rpm
rpm -ivh MySQL-shared-community-5.1.37-0.rhel5.x86_64.rpm
rpm -ivh MySQL-devel-community-5.1.37-0.rhel5.x86_6 ......
MySQLÓÐËÄÖÖBLOBÀàÐÍ:
¡¡¡¡·tinyblob:½ö255¸ö×Ö·û
¡¡¡¡·blob:×î´óÏÞÖÆµ½65K×Ö½Ú
¡¡¡¡·mediumblob:ÏÞÖÆµ½16M×Ö½Ú
¡¡¡¡·longblob:¿É´ï4GB
¡¡¡¡ÔÚÿ¸öMySQLµÄÎĵµ(´ÓMySQL4.0¿ªÊ¼)µÄ½éÉÜÖÐ,Ò»¸ölongblobÁеÄ×î´óÔÊÐí³¤¶ÈÒÀÀµÓÚÔÚ¿Í»§/·þÎñÆ÷ÐÒéÖпÉÅäÖõÄ×î´ó°üµÄ´óСºÍ¿ÉÓÃÄÚ´æÊý¡£
¡¡¡ ......