#!/usr/bin/python
# -*- coding: UTF-8 -*-
import MySQLdb
#打开数据库链接
db = MySQLdb.connect("localhost","root","abc123","tests")
#使用cursor()方法操作来获取游标
cursor = db.cursor()
#使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")
#使用fetchone()方法获取一条数据库
data = cursor.fetchone()
print "Database version :%s"% data
#关闭数据库链接db.close()
相关文章
- 解决Oracle ORA-01033: ORACLE initialization or shutdown in progress错误 和 ORA-01589错误 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项
- MySQL之改_update
- MySQL索引的使用方式和缺点
- MySQL导出数据文件
- MySQL if,ifnull,nullif 函数
- MySQL中的IFNULL,IF,NULLIF函数
- WNMP环境搭建步骤 nginx1.4.3+php-5.3.27+mysql-5.5+RunHiddenConsole
- Mysql5.7自定义函数递归报错1424 Recursive stored functions and triggers are not allowed
- 有关使用phpstudy搭建sqli-lab环境搭建时发生Uncaught Error: Call to undefined function mysql_connect()错误
- mysql if()