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
Ïà¹ØÎĵµ£º
gcc Ç¿´óµÄ±àÒëÆ÷¾Í²»×÷½éÉÜÁË
linuxÏÂÓÃgccÃüÁî±àÒë¶àÏß³ÌC³ÌÐòÎļþºÍº¬ÓÐMySqlÊý¾Ý¿â²Ù×÷Îļþ
1.±àÒë¶àÏß³ÌÎļþ
gcc -o mylti_thread.o multi_thread.c -lpthread
ÆäÖеÄmulti_thread.c±íʾԴÎļþ£¬mylti_thread.o±íʾ±àÒë²úÉúµÄÄ¿±êÎļþ£¬-lpthread±íʾÒýÈë¶àÏ߳̿⣬ÔÚ¡¶Using the GNU Compiler Collection¡·gcc 4. ......
MySQL°²×°Ä¿Â¼ÏµÄDataĿ¼ÖÐ .err´íÎóÐÅÏ¢:
Default storage engine (InnoDB) is not available
½â¾ö°ì·¨:
ɾ³ýÔÚMySQL°²×°Ä¿Â¼ÏµÄDataĿ¼ÖеÄ
ib_logfile0
ib_logfile1
ÖØÐÂÆô¶¯MySQLµÄService ......
¹ØÓÚMYSQLµÄshow status½âÏê
SHOW STATUSÌṩ·þÎñÆ÷µÄ״̬ÐÅÏ¢(Ïómysqladmin extended-statusÒ»Ñù)¡£Êä³öÀàËÆÓÚÏÂÃæµÄÏÔʾ£¬¾¡¹Ü¸ñʽºÍÊý×Ö¿ÉÒÔÓе㲻ͬ£º
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| Aborted_clients | 0 |
| Aborted_connect ......
Á½ÖÖÀàÐÍ×îÖ÷ÒªµÄ²î±ð¾ÍÊÇInnodb Ö§³ÖÊÂÎñ´¦ÀíÓëÍâ¼üºÍÐм¶Ëø.¶øMyISAM²»Ö§³Ö.ËùÒÔMyISAMÍùÍù¾ÍÈÝÒ×±»ÈËÈÏΪֻÊʺÏÔÚСÏîÄ¿ÖÐʹÓá£
ÎÒ×÷ΪʹÓÃMySQLµÄÓû§½Ç¶È³ö·¢£¬InnodbºÍMyISAM¶¼ÊDZȽÏϲ»¶µÄ£¬µ«ÊÇ´ÓÎÒĿǰÔËάµÄÊý¾Ý¿âƽ̨Ҫ´ïµ½ÐèÇó£º99.9%µÄÎȶ¨ÐÔ£¬·½±ãµÄÀ©Õ¹ÐԺ͸߿ÉÓÃÐÔÀ´ËµµÄ»°£¬MyISAM¾ø¶ÔÊÇÎÒµÄÊ×Ñ¡¡£
ÔÒ ......
ÔÎÄÁ´½Ó http://database.51cto.com/art/200904/117957.htm
ÒÔÏÂÊÇÉæ¼°µ½²åÈë±í¸ñµÄ²éѯµÄ5ÖָĽø·½·¨£º
1)ʹÓÃLOAD DATA INFILE´ÓÎı¾ÏÂÔØÊý¾ÝÕ⽫±ÈʹÓòåÈëÓï¾ä¿ì20±¶¡£
2)ʹÓôøÓжà¸öVALUESÁбíµÄINSERTÓï¾äÒ»´Î²åÈ뼸ÐÐÕ⽫±ÈʹÓÃÒ»¸öµ¥ÐвåÈëÓï¾ä¿ì¼¸±¶¡£µ÷Õûbulk_insert_buffer_size±äÁ¿Ò²ÄÜÌá¸ß£¨Ïò°üº¬Ðеıí ......