MySQLdb模块操作
Linux
- 安装mysql: apt-get install mysql-server
- 安装python-mysql模块:apt-get install python-mysqldb
Windows
- 下载安装mysql
- python操作mysql模块:MySQL-python-1.2.3.win32-py2.7.exe 或 MySQL-python-1.2.3.win-amd64-py2.7.exe
- mysql图形界面:Navicat_for_MySQL
安装完成后,导入MySQLdb测试是否安装成功
#!/usr/bin/env python
#coding:utf- import MySQLdb '''
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='07day05db') cur = conn.cursor() reCount = cur.execute('insert into UserInfo(Name,Address) values(%s,%s)',('alex','usa')) conn.commit() cur.close()
conn.close() print reCount
''' '''
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='07day05db') cur = conn.cursor() reCount = cur.execute('delete from UserInfo') conn.commit() cur.close() conn.close() print reCount
''' '''
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='07day05db')
cur = conn.cursor() li =[
('alex','usa'),
('sb','usa'),
]
reCount = cur.executemany('insert into UserInfo(Name,Address) values(%s,%s)',li) conn.commit()
cur.close()
conn.close() print reCount
''' '''
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='07day05db')
cur = conn.cursor() reCount = cur.execute('update UserInfo set Name = %s',('alin',)) conn.commit()
cur.close()
conn.close() print reCount
''' '''
#fetchone/fetchmany(num)
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='07day05db')
cur = conn.cursor() reCount = cur.execute('select * from UserInfo') print cur.fetchone()
print cur.fetchone()
cur.scroll(-,mode='relative')
print cur.fetchone()
print cur.fetchone()
cur.scroll(,mode='absolute')
print cur.fetchone()
print cur.fetchone() cur.close()
conn.close() print reCount
''' #fetchall conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='07day05db')
#cur = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor) #以字典形式,显示结果
cur = conn.cursor() reCount = cur.execute('select Name,Address from UserInfo') nRet = cur.fetchall() cur.close()
conn.close() print reCount
print nRet
for i in nRet:
print i[],i[]
MySQLdb模块操作的更多相关文章
- 12.python笔记之mysqldb模块
一.使用python调用模块操作MYsql 2.x版本使用mysqldb模块 3.x版本使用pymysql模块 1.数据库常用操作: 使用Navicat for MySql软件来操作 show dat ...
- Python的MySQLdb模块安装,连接,操作,增删改
1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本 python -V 检查python版本 2. 安装mysql, 比如安装在/usr/local/my ...
- python操作三大主流数据库(1)python操作mysql①windows环境中安装python操作mysql数据库的MySQLdb模块mysql-client
windows安装python操作mysql数据库的MySQLdb模块mysql-client 正常情况下应该是cmd下直接运行 pip install mysql-client 命令即可,试了很多台 ...
- Python MySQLdb模块连接操作mysql数据库实例_python
mysql是一个优秀的开源数据库,它现在的应用非常的广泛,因此很有必要简单的介绍一下用python操作mysql数据库的方法.python操作数据库需要安装一个第三方的模块,在http://mysql ...
- Python的MySQLdb模块安装
MySQL-python-1.2.1.tar.gz 下载地址:https://pan.baidu.com/s/1kVfH84v 然后解压,打开README(这个其实没有什么鸟用) 里面有安装过程: ...
- Mac MySQLdb模块安装,可算解决了
转载:http://blog.csdn.net/janronehoo/article/details/25207825 短评:这篇文章感觉是比较全面解决Mac MySQLdb模块安装问题的文章了,特别 ...
- Python学习之MySQLdb模块
摘要: MySQLdb模块用于操作mysql数据库.1.安装MySQLdb模块 yum install MySQL-python -y2.操作流程①.导入模块: import MySQLdb②.连接数 ...
- python之mysqldb模块安装
之所以会写下这篇日志,是因为安装的过程有点虐心.目前这篇文章是针对windows操作系统上的mysqldb的安装.安装python的mysqldb模块,首先当然是找一些官方的网站去下载:https:/ ...
- python使用MySQLdb模块连接MySQL
1.安装驱动 目前有两个MySQL的驱动,我们可以选择其中一个进行安装: MySQL-python:是封装了MySQL C驱动的Python驱动:mysql-connector-python:是MyS ...
随机推荐
- PHP 中和 HTTP 相关的函数及使用
① get_headers 方法:取得服务器响应一个 HTTP 请求所发送的所有标头 例如: <?php $httpinfo = get_headers('http://www.baidu.co ...
- Nginx 笔记与总结(3)配置虚拟主机
Nginx 重启的另外一种方式,相当于 kill -HUP `cat /usr/local/nginx/logs/nginx.pid`: /usr/local/nginx/sbin/nginx -s ...
- 获取在attr.xml中声明的主题样式
在换肤时,先在attr.xml中定义Resource的属性名,再到stytle中,根据不同的主题,给属性赋值. 在布局文件中可直接以 android:background="?attr/a ...
- uitextfield输入字符限制
-(UITextField*)createField:(NSString*)placeholder andTag:(int)tag andFont:(double)font{ UITextField ...
- Xamarin 示例Standard Controls报错:xamarin Failed to compile interface file. See Build Output for details
Standard Controls 示例下载地址: http://developer.xamarin.com/content/StandardControls/ Xamarin官网上的IOS示例“St ...
- PHP文件操作 之统计目录大小
<?php //定义一个函数 统计目录大小函数 function dirSize($dirName) { //判断目录是否存在 if (!file_exists($dirName)) { die ...
- 学习VS生活
很多时候,失败的原因归结为一点:我没有时间...代码敲不完,我真的是没有时间么?很多时候是没意识的浪费时间 我每次进教室,总能看到吴刚和赵东亮在敲代码,为啥他们有时间呢?很多时候,时间就像那啥,挤一挤 ...
- Off-heap Memory in Apache Flink and the curious JIT compiler
https://flink.apache.org/news/2015/09/16/off-heap-memory.html Running data-intensive code in the J ...
- oracle创建dblink问题
1.如果在本地"D:\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora"中设置 服务器数据库连接,必须再服务器设置 ...
- volatile in thread
public class TestCalc { public static void main(String[] args) { class StoppableThread extends Threa ...