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 允许我们指定数值字段中的值是否有正负之分或者用零填补。
表列出了各种数值类型以及它们的允许范围和占用的内存空间。
......
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 ......