mysqldb(python mysqldb 安装)

  

使用python 中的MySQLdb模块读取数据,每次都要创建新的连接吗??


  不用重新创建,DBUtil之类的有连接池的都是会保持一定数量的连接,不会每次都重新创建。另外,如果表里增加新的结果,肯定会看到。我这里测试是正常的:  import MySQLdb  import time  connMy = MySQLdb.connect(host="localhost",user="test",passwd="test",db="test")  while True:  cur = connMy.cursor()  cur.execute("select id from test order by id desc LIMIT 5")  ls = [row for row in cur]  print ls  cur.close()  time.sleep(10)  connMy.close()  运行之后:  [(5L,), (4L,), (3L,), (2L,), (1L,)]  [(5L,), (4L,), (3L,), (2L,), (1L,)]  [(5L,), (4L,), (3L,), (2L,), (1L,)]  [(6L,), (5L,), (4L,), (3L,), (2L,)]  [(7L,), (6L,), (5L,), (4L,), (3L,)]  ...  新增加的记录都可以看到。你检查一下SQL语句有没有问题,还有插入新记录的时候是否提交了会话之类的。本身的Python程序是没有问题的  

PHPAdmin是干什么用的/


  就是连接数据库用的  

mysqldb和mysql的区别


  MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的。  mysql 就是mysql数据库了  

python3.4中import MySQLdb与import mysql有区别吗?


  MySQLdb只支持Python2.*,还不支持3.*  可以用PyMySQL代替。安装方法:pip install PyMySQL  然后在需要的项目中,把 __init__.py中添加两行:  import pymysql  pymysql.install_as_MySQLdb()  就可以用 import MySQLdb了。其他的方法与MySQLdb一样。  

mysqldb为什么只返回一条


  mysqldb为什么只返回一条  cursor = conn.cursor()  #创建一个表存储数据  sql_create = "create table if not exists account(nameid int, money varchar(100)) "  #插入两条数据  sql_insert1 = "insert into account(nameid,money) values(13,120)"  sql_insert2 = "insert into account(nameid,money) values(14,10)"  #执行上述sql语句  cursor.execute(sql_create)  cursor.execute(sql_insert1)  cursor.execute(sql_insert2)  conn.close()