ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 数据库 >> MySql >> python 2711 + windows 10 连接 mysql学习记录

python 2711 + windows 10 连接 mysql学习记录(1/4)

来源:网络整理     时间:2016-05-31     关键词:windows 10

本篇文章主要介绍了"python 2711 + windows 10 连接 mysql学习记录",主要涉及到windows 10方面的内容,对于MySql感兴趣的同学可以参考一下: 1. 前言最近在学习mysql 的相关内容, 于是考虑使用 python 去连接他, 学习一下之后发现, 使用python 去连接mysql, 真的好方便啊。2...

1. 前言

最近在学习mysql 的相关内容, 于是考虑使用 python 去连接他, 学习一下之后发现, 使用python 去连接mysql, 真的好方便啊。

2. 基本流程

我们这里使用 3 种途径来连接 mysql, 分别是 connector, mysqldb, torndb
ps: 我们这里选用的数据库表的格式为:
windows10好用吗,windows10官网,微软windows10官网,小米平板1windows10,windows10u盘启动盘,windows10激活工具,windows10金蝶软件,windows10怎么样,windows10激活密钥,windows10下载,windows10系统官网,windows10升级助手,升级windows10,windows10正式版,windows10激活
ps: 图中的这个软件是 mysql workbench, 当然我们也可以使用 cmd控制台, 不过这个界面看上去更加直观一些, 嘻嘻嘻

2.1 mysql connectors

2.1.1 安装配置

- 首先进入 https://www.mysql.com/products/connector/ 页面, 选择相应版本的 python driver 下载安装, 我们这里选用的是 x64, python 2.7 版本的 msi installer, 链接: http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.3-py2.7-winx64.msi

2.1.2 查询

from __future__ import print_function

sql = ('select * from ipdata limit 10')

# mysql-connector
print('mysql-connector'.center(50, '='))
from mysql import connector

cnx = connector.Connect(host="127.0.0.1", user="root", password="zhyh2010", database="pythontest", charset = "utf8")
cnx.autocommit = True
db0 = cnx.cursor()

db0.execute(sql)
for row in db0:
    print(*row)

2.1.3 插入数据

相关图片

相关文章