易截截图软件、单文件、免安装、纯绿色、仅160KB

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

初探MYSQL。在我有效地心中留下一道阴影……

为什么这么说呢。因为啊我写我公司的查PV的数据时,发现表的功能不是很全,让我用一句话写出那么老牛的SQL语句真的好难。
真么着吧,我写出我这句话来看一看。
<?php
//########################2010-1-24 22:48
//#######################数据库查询
//######################本程序共有3个sql分别为sql,sql5,sql ......

MySQL 的表级锁

 在开发项目时,遇到一个问题,就是要随机读取一张表的部分记录,并update设置为不可在读,这里就有一个问题,可能多个人同时随机到相同的记录,并重复做update操作,引起数据脏读和重复操作,
因此考虑给表加锁。但是采用了MyISAM,不支持事务,只能加表级锁,而且别人连读的权限都没有。下面是2个测试文件,在firef ......

优化MySQL插入方法的五个妙招

原文链接 http://database.51cto.com/art/200904/117957.htm
以下是涉及到插入表格的查询的5种改进方法:
1)使用LOAD DATA INFILE从文本下载数据这将比使用插入语句快20倍。
2)使用带有多个VALUES列表的INSERT语句一次插入几行这将比使用一个单行插入语句快几倍。调整bulk_insert_buffer_size变量也能提高(向包含行的表 ......

mysql问题

重装时出现could not start the service mysql error:0的错误时
在控制面板中运行添加删除程序,将mysql卸载;
卸载后打开注册表,查看HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services 下的键值,如果有相关mysql键值(mysql、mysqladmin)则删掉,即可;
重启,将mysql的安装残余目录删掉 (查看服务,此时服务中已没 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号