1.下载安装connector/python

地址:https://dev.mysql.com/downloads/connector/python/

下载的版本(mysql-connector-python-8.0.15-py3.5-windows-x86-64bit.msi)  下载后根据提示安装

2.数据库中数据

3.使用python中的mysql.connector模块操作mysql

import mysql.connector                 

# mysql1.py
config = {
'host': '127.0.0.1',
'user': 'root',
'password': 'root',
'port': 3306,
'database': 'test',
'charset': 'utf8'
}
try:
cnn = mysql.connector.connect(**config)
except mysql.connector.Error as e:
print('connect fails!{}'.format(e))
cursor = cnn.cursor()
try:
sql_query = 'select name,age from stu ;'
cursor.execute(sql_query)
for name, age in cursor:
print (name, age)
except mysql.connector.Error as e:
print('query error!{}'.format(e))
finally:
cursor.close()
cnn.close()

结果:

(u'xiaoming', 10)
(u'rose', 18)
(u'jack', 19)
(u'fang', 20)
(u'Liang', 40)
(u'Age', None)

  

mysql-connector/python使用示例的更多相关文章

  1. Snippet: Fetching results after calling stored procedures using MySQL Connector/Python

    https://geert.vanderkelen.org/2014/results-after-procedure-call/ Problem Using MySQL Connector/Pytho ...

  2. Installing MySQL Connector/Python using pip v1.5

    The latest pip versions will fail on you when the packages it needs to install are not hosted on PyP ...

  3. MySQL Connector/Python 接口 (一)

    这里仅介绍 MySQL 官方开发的 Python 接口,参见这里: https://dev.mysql.com/doc/connector-python/en/ Chapter 1 Introduct ...

  4. MySQL Connector/Python 接口 (二)

    连接数据库 本文参见这里,示例如何连接MySQL 数据库. import mysql.connector from mysql.connector import errorcode # 连接数据库需要 ...

  5. MySQL Connector/Python 安装、测试

         安装Connector/Python: # wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-pyth ...

  6. MySQL Connector/Python 接口 (三)

    本文参见这里. 使用缓冲的 cursor,下例给从2000年加入公司并且还在公司的员工薪水从明天起加15% from __future__ import print_function from dec ...

  7. python使用mysql的三个模块:mysql.connector、sqlalchemy、MySQLdb

    在python中使用mysql其实很简单,只要先安装对应的模块即可,那么对应的模块都有什么?官方也没指定也没提供,pcat就推荐自己遇到的3个模块:mysql.connector.sqlalchemy ...

  8. MySQL:Download Connector/Python

    MySQL Connector / Python是用于Python平台和开发的标准化数据库驱动程序. 此外,MySQL Connector / Python 8.0支持使用MySQL Server 8 ...

  9. mysql.connector操作mysql的blob值

    This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...

  10. How to Access MySQL with Python Version 3.4

    http://askubuntu.com/questions/630728/how-to-access-mysql-with-python-version-3-4 How to Access MySQ ...

随机推荐

  1. code::blocks学习

    code::block不能调试问题 今天在codeblock不能进行调试,百度总结如下: 1 进行调试的必须是一个project而不能是一个单一的cpp文件. 2 project的路径不能包含中文,尽 ...

  2. “全栈2019”Java第十七章:赋值运算符和算术运算符

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  3. LoadRunner12_脚本中运行JavaScript

    版权声明:本文为博主原创文章,未经博主允许不得转载. [系统及软件配置] LR版本:12.53 JDK版本:1.8 函数:web_js_run,该函数仅在LR12版本提供支持,LR11不支持JavaS ...

  4. JQuery实现全选、反选和取消功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Centos6和7的区别

    1.init系统 Linux 操作系统的启动首先从 BIOS 开始,接下来进入 boot loader,由 bootloader 载入内核,进行内核初始化.内核初始化的最后一步就是启动 pid 为 1 ...

  6. sed用法——在指定行后面添加内容

    文档内容如下: # cat 123.txt linuxciscohuaweinetworksystem 1. 使用sed命令在cisco行下面添加CCIE: # sed -i "/cisco ...

  7. 求二叉树第K层的节点个数+求二叉树叶子节点的个数

    size_t _FindLeafSize(Node* root)     //求二叉树叶子节点的个数    {        //static size_t count = 0;        if ...

  8. [ActionSprit 3.0] FMS客户端与服务器端交互(传参)

    客户端as: import flash.net.NetConnection; import flash.events.NetStatusEvent; var nc:NetConnection = ne ...

  9. [Swift实际操作]八、实用进阶-(7)使用通知的方法进行对象间的消息传递

    本文将为你演示,如何使用Notification Center进行消息的传递.通知中心是一个调度消息通知的类,采用单例设计模式,实现数据传递,回调等功能.首先打开自定义视图的代码文件(CustomVi ...

  10. iOS 开发中类似上下滚动弹幕实现原理

    #mark ---滚动弹幕 列表中留有7条记录  大于7条时删除并指引表视图向上滑动 - (void)addRowActionWithContent:(NSString *)str { if (sel ...