【安装】
安装MySQL
安装MySQL不用多说了,下载下来安装就是,没有特别需要注意的地方。
一个下载地址:点击打开链接
【样例】
# coding=utf-8
import MySQLdb
#查询数量
def Count(cur):
count=cur.execute('select * from Student')
print 'there has %s rows record' % count
#插入
def Insert(cur):
sql = "insert into Student(ID,Name,Age,Sex)values(%s,%s,%s,%s)"
param = (2,'xiaoming',24,'boy')
cur.execute(sql,param)
#查询
def Select(cur):
n = cur.execute("select * from Student")
print "------"
for row in cur.fetchall():
for r in row:
print r
print "------"
#更新
def Update(cur):
sql = "update Student set Name = %s where ID = 2"
param = ("xiaoxue")
count = cur.execute(sql,param)
#删除
def Delete(cur):
sql = "delete from Student where Name = %s"
param =("xiaoxue")
n = cur.execute(sql,param)
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='python',port=3306)
cur=conn.cursor()
#数量
Count(cur)
#查询
Select(cur)
#插入
Insert(cur)
print "插入之后"
#查询
Select(cur)
#更新
Update(cur)
print "更新之后"
#查询
Select(cur)
#删除
Delete(cur)
print "删除之后"
#查询
Select(cur)
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
分享到:
相关推荐
python连接mysql,操作mysql函数封装
学生信息管理系统(python+GUI+mysql).zip,学生信息管理系统(python+GUI+mysql).zip,学生信息管理系统(python+GUI+mysql).zip 学生信息管理系统(python+GUI+mysql).zip,学生信息管理系统(python+GUI+mysql).zip,...
最近用到Python操作数据库,MySql的操作封装类,简单写了一个Mysql封装操作类,分享一下,需要安装pymsql,安装方法:https://blog.csdn.net/sinat_28984567/article/details/105316092
python读写MySQL数据库操作,读操作,写操作,python读写MySQL数据库操作
Django + python + mysql的在线考试系统源码 Django + python + mysql的在线考试系统源码 Django + python + mysql的在线考试系统源码 Django + python + mysql的在线考试系统源码 Django + python + mysql的...
python示例代码——mysql操作
Python操作Mysql实例代码教程.pdf
适合新手,图书馆管理系统Python+MySQL+tkinter图形化界面+数据库+源码(注释详细) 适合新手,图书馆管理系统Python+MySQL+tkinter图形化界面+数据库+源码(注释详细) 适合新手,图书馆管理系统Python+MySQL+...
python连接mysql模块mysql-connector-python-2.1.1.tar.gz
自己收集编写的python操作mysql函数,奉献给大家,该文件包含用python处理mysql的查、增、改、删、命名、排序等操作的函数,mysql数据库操作的各种sql语句可供参考。
在Windows平台上安装mysql模块用于Python开发 用python连接mysql的时候,需要用的安装版本,源码版本容易有错误提示。下边是打包了32与64版本。 MySQL-python-1.2.3.win32-py2.7.exe MySQL-python-1.2.3.win-amd64-...
python 操作mysql 安装和使用
python操作MySQL实例教程,简单明了
PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb。 PyMySQL 遵循 Python 数据库 API v2.0 规范,并包含了 pure-Python MySQL 客户端库。
使用Python连接和操作MySQL数据库工具包-PyMySQL (1)安装Python (2)安装MySQL (3)安装PyMySQL (4)创建连接 (5)Python代码操作数据库 1. 引入模块MySQLdb:import MySQLdb 2. 连接到数据库和建立游标:...
python操作mysql数据库上课讲义.pdf
将下载的MySQL-python-1.2.5的文件解压,然后打开编辑器编辑setup_posix,其中有一行mysql_config.path = "mysql_config",改为mysql_config.path = "/usr/local/Cellar/mysql-connector-c/6.1.11/bin/mysql_config...
非MySQL安装MySQL-python,有时不是数据库为封装的MySQL时,可以通过yum -y install mysql-devel 但有时不行,这是可按文档去更改MySQL-python
本例中使用Python语言,基于Pymysql包,对图片进行存取操作
包含python2.6操纵MySQL的安装文档和windows下的安装包。