python连接MySQL
2017-03-26 17:48
197 查看
使用Python连接MySQL
安装MySQL
yum install -y mysql-server mysql-devel
安装MySQL-python驱动
pip install MySQL-python
测试
➜ 2-3_Django ipython Python 2.7.11 (default, Mar 7 2017, 08:25:27) Type "copyright", "credits" or "license" for more information. IPython 5.3.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import MySQLdb In [2]:
操作示例
#coding=utf-8 import MySQLdb conn= MySQLdb.connect( host='localhost', port = 3306, user='root', passwd='123456', db ='test', ) cur = conn.cursor() # 创建数据表 cur.execute("create table student(id int ,name varchar(20),class varchar(30),age varchar(10))") # 插入一条数据 cur.execute("insert into student values('2','Tom','3 year 2 class','9')") #修改查询条件的数据 # cur.execute("update student set class='3 year 1 class' where name = 'Tom'") #删除查询条件的数据 # cur.execute("delete from student where age='9'") cur.close() conn.commit() conn.close()
相关错误解决方法
编译时报如下错误‘_mysql_connectionobject’ has no member named ‘open’
http://f.dataguru.cn/thread-132530-1-1.html
相关文章推荐
- python django MySQLdb 连接 mysql 5.5 中文乱码问题的解决
- python模块使用之MySQLdb 连接 MySQL 数据库
- python django mysql 连接
- python 连接操作 mysql(数据库)
- python连接mysql简单小程序
- Python3连接MySQL(pymysql)模拟转账实现代码
- python连接Mysql操作
- 实现Python连接Mysqln以及应用
- MySQL 连接Python 的2 种方法
- python——文件、os模块、异常,连接mysql
- python3连接mysql - driver
- python、mysql安装及连接
- 安装MySQL-python(MySQLdb)时报错,找不到libmysqlclient_r.so.16动态连接库
- Python33 连接MySQL
- 简单的Python连接MySQL和EXCEL示例
- python连接mysql ---处理数据
- python 连接 MySQL 中文乱码
- python 环境搭建 ,连接 mysql
- Python 3.2: 使用pymysql连接Mysql
- web测试常用python代码——mysql连接以及语句执行