MySQL Python教程(4)
Class cursor.MySQLCursorBuffered
该类从Class cursor.MySQLCursorBuffered继承,如果需要,可以在执行完SQL语句后自动缓冲结果集合。
import mysql.connector
cnx = mysql.connector.connect()
# Only this particular cursor will buffer results
cnx.cursor(buffered=True)
# All cursors will be buffering by default
cnx2 = mysql.connector.connect(buffered=True)
Class cursor.MySQLCursorPrepared
该类继承cursor.MySQLCursor,使用二进制协议执行prepare statement
使用方法:
import mysql.connector
from mysql.connector.cursor import MySQLCursorPrepared
cnx = mysql.connector.connect(database='employees')
cursor = cnx.cursor(cursor_class=MySQLCursorPrepared)
此时cursor为MySQLCursorPrepared对象。
举例:
cursor = cnx.cursor(cursor_class=MySQLCursorPrepared)
stmt = "SELECT fullname FROM employees WHERE id = ?" # (1)
cursor.execute(stmt, (5,)) # (2)
# ... fetch data ...
cursor.execute(stmt, (10,)) # (3)
# ... fetch data ...
Class constants.ClientFlag
This class provides constants defining MySQL client flags that can be used when the connection is established to configure the session.
>>> import mysql.connector
>>> mysql.connector.ClientFlag.FOUND_ROWS
2
Class constants.FieldType
该类不能被实例化,支持所有MySQL的数据类型。
from __future__ import print_function
import mysql.connector
from mysql.connector import FieldType
cnx = mysql.connector.connect(user='scott', database='test')
cursor = cnx.cursor()
cursor.execute(
"SELECT DATE(NOW()) AS `c1`, TIME(NOW()) AS `c2`, "
"NOW() AS `c3`, 'a string' AS `c4`, 42 AS `c5`")
rows = cursor.fetchall()
for desc in cursor.description:
colname = desc[0]
coltype = desc[1]
print("Column {} has type {}".format(
colname, FieldType.get_info(coltype)))
cursor.close()
cnx.close()
Class constants.SQLMode
提供所有已知的SQL服务器模式。具体参见
http://dev.mysql.com/doc/refman/5.6/en/server-sql-mode.html
Class constants.CharacterSet
提供MYSQL的字符集和默认的collations。参见Method MySQLConnection.set_charset_collation
Class constants.RefreshOption
该类提供多种flush的操作。
RefreshOption.GRANT
Refresh the grant tables, like FLUSH PRIVILEGES.
RefreshOption.LOG
Flush the logs, like FLUSH LOGS.
RefreshOption.TABLES
Flush the table cache, like FLUSH TABLES.
RefreshOption.HOSTS
Flush the host cache, like FLUSH HOSTS.
RefreshOption.STATUS
Reset status variables, like FLUSH STATUS.
RefreshOption.THREADS
Flush the thread cache.
RefreshOption.SLAVE
On a slave replication server, reset the master server information and restart the slave, like RESET SLAVE.
RefreshOption.MASTER
On a master replication server, remove the binary log files listed in the binary log index and truncate the index file, like RESET MASTER.
MySQL Python教程(4)的更多相关文章
- MySQL Python教程(1)
首先对于数据库的基本操作要有一定基础,其次了解Python的基础语法. 建议先阅读MysqL中文教程http://doc.mysql.cn/mysql5/refman-5.1-zh.html-chap ...
- MySQL Python教程(2)
mysql官网关于python的API是最经典的学习材料,相信对于所有函数浏览一遍以后,Mysql数据库用起来一定得心应手. 首先看一下Connector/Python API包含哪些类和模块. Mo ...
- MySQL Python教程(3)
Class cursor.MySQLCursor 具体方法和属性如下:Constructor cursor.MySQLCursorMethod MySQLCursor.callproc(procnam ...
- Python教程:操作数据库,MySql的安装详解
各位志同道合的同仁请点击上方关注 本教程是基于Python语言的深入学习.本次主要介绍MySql数据库软件的安装.不限制语言语法,对MySql数据库安装有疑惑的各位同仁都可以查看一下. 如想查看学习P ...
- 数据库 之MySQL 简单教程
So Easy系列之MySQL数据库教程 1. 数据库概述 1.1. 数据库概述 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和 ...
- Python教程:连接数据库,对数据进行增删改查操作
各位志同道合的同仁可以点击上方关注↑↑↑↑↑↑ 本教程致力于程序员快速掌握Python语言编程. 本文章内容是基于上次课程Python教程:操作数据库,MySql的安装详解 和python基础知识之上 ...
- Windows下安装MySQL详细教程
Windows下安装MySQL详细教程 1.安装包下载 2.安装教程 (1)配置环境变量 (2)生成data文件 (3)安装MySQL (4)启动服务 (5)登录MySQL (6)查询用户密码 (7 ...
- MySQL 【教程二】
MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: # CREATE TABLE table_name (c ...
- python入门灵魂5问--python学习路线,python教程,python学哪些,python怎么学,python学到什么程度
一.python入门简介 对于刚接触python编程或者想学习python自动化的人来说,基本都会有以下python入门灵魂5问--python学习路线,python教程,python学哪些,pyth ...
随机推荐
- CF721C. Journey
传送门 说实话,这是一道非常简单的DP题,简单到如果放到NOIp第二题可能都有些差强人意,然而我写崩了. 所以简单记录一下. 需要注意的是,这道题的DP应该是从$N$点开始,以1为边界,满足最短路的三 ...
- UVA1395 Slim Span(枚举最小生成树)
题意: 求最小生成树中,最大的边减去最小的边 最小值. 看了题解发现真简单=_= 将每条边进行从小到大排序,然后从最小到大一次枚举最小生成树,当构成生成树的时候,更新最小值 #include < ...
- Django_collections01
python manage.py flush python manage.py changepassword username python manage.py createsuperuser pyt ...
- Spring 通过maven pom文件配置初始化
spring对bean的生命周期管理的比较精细,并不是单纯的new()实例化. 1,找到class配置信息并将其实例化 2,受用依赖注入,按照配置信息,配置bean的所有属性; 在一个开始使用前可以用 ...
- (翻译)如何对python dict 类型按键(keys)或值(values)排序
如何对dict类型按键(keys)排序(Python 2.4 或更高版本): mydict = {'carl':40, 'alan':2, 'bob':1, 'danny':3} for key in ...
- ubuntu下增加中文编码
在Ubuntu中,利用命令:locale,来查看系统的语言环境 参考:http://blog.chinaunix.net/uid-94449-id-2002589.html Windows的默认编码为 ...
- C++ 泛型基础
C++ 泛型基础 泛型的基本思想:泛型编程(Generic Programming)是一种语言机制,通过它可以实现一个标准的容器库.像类一样,泛型也是一种抽象数据类型,但是泛型不属于面向对象,它是面向 ...
- ecshop订单-》待付款,待发货,待收货,收货确认
// 订单 待付款.待发货.待收货.确认收货 public function get_serch_order($type/*,$limit_statrt,$limit_end,$serch*/){ $ ...
- ecshop循环foreach,iteration,key,index
转载: 最近刚接触ecshop不久,感觉是非常的强大,做商城网站,整个流程都差不多搞好了,就是支付流程要自己完善完善,不过也有不足,文章功能还不够好. 通过几天的应用,总结出了ec模版中foreach ...
- 居于Web的进度条实现思路(下载百分比)
http://www.cnblogs.com/wfyfngu/p/4866434.html 在传统桌面项目中,进度条随处可见,但作为一个很好的用户体验,却没有在如今主流的B/S程序中得到传承,不能不说 ...