python 操作mysql資料庫
#!/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()
相關文章
- Python之 操作 MySQL 資料庫PythonMySql資料庫
- 01-python操作Mysql資料庫PythonMySql資料庫
- python操作MySQL資料庫連線(pymysql)PythonMySql資料庫
- python資料庫-MySQL資料庫高階查詢操作(51)Python資料庫MySql
- MySQL 資料庫操作MySql資料庫
- 全棧 – 12 資料庫 用Python操作MySQL全棧資料庫PythonMySql
- Python操作MySQL資料庫的5種方式PythonMySql資料庫
- Python 連線mysql資料庫進行操作PythonMySql資料庫
- Mysql資料庫操作命令MySql資料庫
- PHP操作MySQL資料庫PHPMySql資料庫
- MySQL資料庫常用操作MySql資料庫
- python的ORM技術:使用sqlalchemy操作mysql資料庫PythonORMMySql資料庫
- Python 利用pymysql和openpyxl操作MySQL資料庫並插入Excel資料PythonMySql資料庫Excel
- Python 操作 SQLite 資料庫PythonSQLite資料庫
- Python操作SQLite資料庫PythonSQLite資料庫
- python操作mongodb資料庫PythonMongoDB資料庫
- mysql資料庫基本操作(五)MySql資料庫
- mysql資料庫基本操作(三)MySql資料庫
- mysql資料庫基本操作(四)MySql資料庫
- 02、MySQL—資料庫基本操作MySql資料庫
- mysql資料庫基本操作(六)MySql資料庫
- python介面自動化(三十八)-python操作mysql資料庫(詳解)PythonMySql資料庫
- python+資料庫(三)用python對資料庫基本操作Python資料庫
- Python 資料庫騷操作 — RedisPython資料庫Redis
- Python 資料庫騷操作 -- RedisPython資料庫Redis
- Python 資料庫騷操作 -- MongoDBPython資料庫MongoDB
- Python資料庫MongoDB騷操作Python資料庫MongoDB
- Python操作MongoDB文件資料庫PythonMongoDB資料庫
- Mysql資料庫基礎操作命令MySql資料庫
- MySQL資料庫操作、儲存引擎MySql資料庫儲存引擎
- Python連線MySQL資料庫PythonMySql資料庫
- Python操作三大主流資料庫Python資料庫
- Python操作Redis快取資料庫PythonRedis快取資料庫
- 2.資料庫Mysql--------基本操作資料庫MySql
- mysqlclient操作MySQL關係型資料庫MySqlclient資料庫
- SQLALchemy操作MySQL關係型資料庫MySql資料庫
- Go語言中mysql資料庫操作(一)GoMySql資料庫
- python資料插入連線MySQL資料庫PythonMySql資料庫
- Python 操作 mysql 資料庫,wait_timeout 後報什麼錯誤PythonMySql資料庫AI