操作MySql
2015-07-31 23:32
931 查看
1.使用pyMySQL操作数据库,下载
点击打开链接
2.解压后在跟目录
重启一下py shell
3.例子
参考资料:
Resources
DB-API 2.0: http://www.python.org/dev/peps/pep-0249
MySQL Reference Manuals: http://dev.mysql.com/doc/
MySQL client/server protocol: http://dev.mysql.com/doc/internals/en/client-server-protocol.html
PyMySQL mailing list: https://groups.google.com/forum/#!forum/pymysql-users
点击打开链接
2.解压后在跟目录
py setup.py install
重启一下py shell
3.例子
import pymysql.cursors connection = pymysql.connect(host='localhost',user='root', password='111111',db='pyDB', charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor) try: # with connection.cursor() as cursor: # sql = "insert into users(email,password) values(%s,%s)" # cursor.execute(sql,('webmaster@python.org','very-secret')) # connection.commit() with connection.cursor() as cursor: sql = 'SELECT * FROM USERS U WHERE U.ID > 0' cursor.execute(sql) result = cursor.fetchone() print(result) finally: connection.close()
参考资料:
Resources
DB-API 2.0: http://www.python.org/dev/peps/pep-0249
MySQL Reference Manuals: http://dev.mysql.com/doc/
MySQL client/server protocol: http://dev.mysql.com/doc/internals/en/client-server-protocol.html
PyMySQL mailing list: https://groups.google.com/forum/#!forum/pymysql-users
相关文章推荐
- Mysql之查询、where、常用函数、having
- Mysql 5.7.7
- Mysql字符集以及校对规则
- excel导入MySQL 学习
- Mysql的SQL_MODE
- MySQL点滴学习之日志管理
- MySQL点滴学习之索引类型
- Mysql 存储过程中应用事务
- Mysql Client
- mysql ERROR 1049 (42000): Unknown database '******' ”错误处理办法
- MySQL数据库的基础操作(建表,建库,插入,删除)
- mysql登录
- mysql having 与 where
- MySQL使用mysqlimport命令导入文本文件
- MySql存储过程动态创建表并插入数据
- 卸载并清理mysql
- 关于2G以上文本文件的MYSQL数据导入 mysql
- (一)mybatis+mysql 基本环境搭建
- mysql的使用和sql语言的学习
- 集群LVS 实现数据共享