[Python] python操作mysql数据库的简单范例演示 →→→→→进入此内容的聊天室

来自 , 2020-08-05, 写在 Python, 查看 102 次.
URL http://www.code666.cn/view/43c65662
  1. #!/usr/bin/python
  2.  
  3. import MySQLdb
  4.  
  5. # Open database connection
  6. db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )
  7.  
  8. # prepare a cursor object using cursor() method
  9. cursor = db.cursor()
  10.  
  11. # execute SQL query using execute() method.
  12. cursor.execute("SELECT VERSION()")
  13.  
  14. # Fetch a single row using fetchone() method.
  15. data = cursor.fetchone()
  16.  
  17. print "Database version : %s " % data
  18.  
  19. # disconnect from server
  20. db.close()
  21.  
  22. #//python/8343

回复 "python操作mysql数据库的简单范例演示"

这儿你可以回复上面这条便签

captcha