farcepest / MySQLdb1

MySQL database connector for Python (legacy version)
https://sourceforge.net/projects/mysql-python/
666 stars 318 forks source link

Select returns nothing on Fedora22 and MySQL 5.7 #117

Closed sunzhaoyang closed 8 years ago

sunzhaoyang commented 8 years ago

Env

$uname -a
Linux backup92 4.3.6-201.fc22.x86_64 #1 SMP Mon Feb 22 13:39:09 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
(everest-dev-env)
[root@backup92 /root]
$pip list |grep -i mysql
MySQL-python (1.2.5)
mysqlclient (1.3.7)
(everest-dev-env)
[root@backup92 /root]
$rpm -qa |grep mysql
mysql-community-devel-5.7.13-1.fc22.x86_64
mysql57-community-release-fc22-8.noarch
mysql-community-client-5.7.13-1.fc22.x86_64
mysql-community-libs-5.7.13-1.fc22.x86_64
mysql-community-server-5.7.13-1.fc22.x86_64
mysql-community-libs-compat-5.7.13-1.fc22.x86_64
mysql-community-common-5.7.13-1.fc22.x86_64

Table

CREATE TABLE `qb_users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(24) NOT NULL DEFAULT '',
  `auth` int(11) NOT NULL,
  `createtime` datetime NOT NULL,
  `password` varchar(64) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

My test code:

import MySQLdb

ip = '127.0.0.1'
passwd = '111'
user = 'test'
db = 'test'

conn_1 = MySQLdb.connect(host=ip, user=user, passwd=passwd, db=db)
cursor_1 = conn_1.cursor(cursorclass=MySQLdb.cursors.DictCursor)

conn_2 = MySQLdb.connect(host=ip, user=user, passwd=passwd, db=db)
cursor_2 = conn_2.cursor(cursorclass=MySQLdb.cursors.DictCursor)

conn_3 = MySQLdb.connect(host=ip, user=user, passwd=passwd, db=db)
cursor_3 = conn_3.cursor(cursorclass=MySQLdb.cursors.DictCursor)

# Important
cursor_1.execute('SELECT * FROM qb_users')

cursor_2.execute(
    "INSERT INTO qb_users(username, password, auth, createtime) VALUES ('111','222',1,'2016-01-01 00:00:00');")
user_id = cursor_2.lastrowid
conn_2.commit()

print user_id

cursor_1.execute('SELECT * FROM qb_users where id=%d' % user_id)
print cursor_1.fetchall()

cursor_3.execute('SELECT * FROM qb_users where id=%d' % user_id)
print cursor_3.fetchall()

Output:

21
()  # cursor_1 returns nothing .
({'username': '111', 'password': '222', 'id': 21L, 'auth': 1L, 'createtime': datetime.datetime(2016, 1, 1, 0, 0)},)

I had tested on redhat7.2 and everthing is ok.

methane commented 8 years ago

That's intended behavior of "repeatable read" transaction isolation level. It's default of MySQL.

I suppose you used MyISAM on old environment. Otherwise, RedHat 7.2 has very customized configuration.

sunzhaoyang commented 8 years ago

Yes, my fault, thanks !