python 操作mysql数据库
来源:互联网 发布:linux 自动启动服务 编辑:程序博客网 时间:2024/06/11 01:31
#!/usr/bin/env python
import MySQLdb
db = MySQLdb.connect("192.168.74.130","root","l","hjliu")
cursor=db.cursor()
cursor.execute("select version()")
data=cursor.fetchone()
print "Database version : %s " % data
#cursor.execute("drop table if exists EMPLOYEE");
sql = "CREATE TABLE if not exists EMPLOYEE(\
first_name char(20) not null,\
last_name char(20),\
age int,\
sex char(1),\
income float)"
cursor.execute(sql)
sql="insert into EMPLOYEE(first_name, last_name, age, sex, income) values ('mac', 'mohan', 20, 'M', 2000), ('mac2', 'mohan', 20, 'M', 2000),('mac1', 'mohan', 20, 'M', 2000)"
cursor.execute(sql)
sql="select * from EMPLOYEE\
WHERE income > '%d'" % (1000)
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
fname = row[0]
lname = row[1]
age = row[2]
sex = row[3]
income = row[4]
print "fname = %s, lname=%s, age=%d, sex=%s, income=%d" %\
(fname, lname, age, sex, income)
db.commit();
db.close()
import MySQLdb
db = MySQLdb.connect("192.168.74.130","root","l","hjliu")
cursor=db.cursor()
cursor.execute("select version()")
data=cursor.fetchone()
print "Database version : %s " % data
#cursor.execute("drop table if exists EMPLOYEE");
sql = "CREATE TABLE if not exists EMPLOYEE(\
first_name char(20) not null,\
last_name char(20),\
age int,\
sex char(1),\
income float)"
cursor.execute(sql)
sql="insert into EMPLOYEE(first_name, last_name, age, sex, income) values ('mac', 'mohan', 20, 'M', 2000), ('mac2', 'mohan', 20, 'M', 2000),('mac1', 'mohan', 20, 'M', 2000)"
cursor.execute(sql)
sql="select * from EMPLOYEE\
WHERE income > '%d'" % (1000)
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
fname = row[0]
lname = row[1]
age = row[2]
sex = row[3]
income = row[4]
print "fname = %s, lname=%s, age=%d, sex=%s, income=%d" %\
(fname, lname, age, sex, income)
db.commit();
db.close()
阅读全文
0 0
- Python操作Mysql数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python操作MySQL数据库
- python 操作mysql 数据库
- python操作mysql数据库
- python 操作 mysql数据库
- python操作MySQL数据库
- python操作MySQL数据库
- Python操作MySQL数据库
- Python操作mysql数据库
- python操作MySQL数据库
- android 仿iphoneX上滑退出应用动画(二)
- plsql如何执行sql命令及oracle数据库用户的授权
- python脚本工作实例
- A Closer Look At Hub, Switch And Router
- Kotlin中的“==”和“===”
- python 操作mysql数据库
- web前端的一些小知识
- Entity Framework中的字符串插值引发担忧
- Java多线程系列--“JUC集合”03之 CopyOnWriteArraySet
- ASP.NET Core 运行原理剖析
- WebSocket In ASP.NET Core(二)
- asp.net core AuthenticationMiddleware 在WebApi中的的使用
- Configuration Extensions
- 手把手教你使用spring cloud+dotnet core搭建微服务架构:服务治理(-)