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模块操作的更多相关文章

  1. 12.python笔记之mysqldb模块

    一.使用python调用模块操作MYsql 2.x版本使用mysqldb模块 3.x版本使用pymysql模块 1.数据库常用操作: 使用Navicat for MySql软件来操作 show dat ...

  2. Python的MySQLdb模块安装,连接,操作,增删改

    1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本     python -V   检查python版本 2. 安装mysql, 比如安装在/usr/local/my ...

  3. python操作三大主流数据库(1)python操作mysql①windows环境中安装python操作mysql数据库的MySQLdb模块mysql-client

    windows安装python操作mysql数据库的MySQLdb模块mysql-client 正常情况下应该是cmd下直接运行 pip install mysql-client 命令即可,试了很多台 ...

  4. Python MySQLdb模块连接操作mysql数据库实例_python

    mysql是一个优秀的开源数据库,它现在的应用非常的广泛,因此很有必要简单的介绍一下用python操作mysql数据库的方法.python操作数据库需要安装一个第三方的模块,在http://mysql ...

  5. Python的MySQLdb模块安装

    MySQL-python-1.2.1.tar.gz  下载地址:https://pan.baidu.com/s/1kVfH84v 然后解压,打开README(这个其实没有什么鸟用) 里面有安装过程: ...

  6. Mac MySQLdb模块安装,可算解决了

    转载:http://blog.csdn.net/janronehoo/article/details/25207825 短评:这篇文章感觉是比较全面解决Mac MySQLdb模块安装问题的文章了,特别 ...

  7. Python学习之MySQLdb模块

    摘要: MySQLdb模块用于操作mysql数据库.1.安装MySQLdb模块 yum install MySQL-python -y2.操作流程①.导入模块: import MySQLdb②.连接数 ...

  8. python之mysqldb模块安装

    之所以会写下这篇日志,是因为安装的过程有点虐心.目前这篇文章是针对windows操作系统上的mysqldb的安装.安装python的mysqldb模块,首先当然是找一些官方的网站去下载:https:/ ...

  9. python使用MySQLdb模块连接MySQL

    1.安装驱动 目前有两个MySQL的驱动,我们可以选择其中一个进行安装: MySQL-python:是封装了MySQL C驱动的Python驱动:mysql-connector-python:是MyS ...

随机推荐

  1. 【液晶模块系列基础视频】4.4.X-GUI图形界面库-画tab函数简介

    [液晶模块系列基础视频]4.4.X-GUI图形界面库-画tab函数简介 ============================== 技术论坛:http://www.eeschool.org 博客地址 ...

  2. ubuntu安装chrome

    1.在Google chrome上面下载Chrome浏览器.选择正确的版本,我电脑是64位的所以选择的是[64 bit .deb (适用于 Debian/Ubuntu)]. google-Chrome ...

  3. Ubuntu 安装 ImageMagic(6.9.1-6)及 PHP 的 imagick (3.0.1)扩展

    关于 ImageMagic 和 imagick 的介绍,见<图片处理神器ImageMagick以及PHP的imagick扩展> 和 <Ubuntu下安装ImageMagick和Mag ...

  4. Shell-bash中特殊字符汇总[转]

    转自http://www.linuxidc.com/Linux/2015-08/121217.htm 首先举例一个bash脚本 #!/bin/bash file=$1 files=`find / -n ...

  5. PHP学习(三)----面向对象

    首先,还是建立一个好的理解模型: 1.什么是面向对象? 面向对象分为两个部分,那就是:什么是对象和什么是面向? 什么是对象: 对象的出现就是为了用代码更好的绘制我们现有的世界.那到底什么是对象呢? 一 ...

  6. IIS7 .NET Runtime version 2.0.50727.5420 - 执行引擎错误(000007FEE77AAF0E) (80131506)

    装完系统,配置完IIS,发现.NET程序报503错误,出错后连接池自动关闭 这个程序是需要连接access数据库的,打开系统日志发现错误如下: 错误应用程序名称: w3wp.exe,版本: 7.5.7 ...

  7. java Direct Buffer

    public static ByteBuffer allocate (int capacity)       //性能低于下面的Direct,因为是把内存建立在JVM堆上,容易被GC回收,可能需要多次 ...

  8. [LeetCode]题解(python):062 Unique path

    题目来源 https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m x  ...

  9. (lleetcode)Merge Sorted Array

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

  10. sqlserver 四舍五入(转)

    select   cast(round(12.5,2)   as   numeric(5,2)) 解释: round()函数,是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入 ...