1. python 与mysql 连接及操作,直接上代码,简单直接高效:

import MySQLdb

try:
conn = MySQLdb.connect(host='localhost',user='root',passwd='×××××',db='test',charset='utf8')
cur = conn.cursor()
cur.execute('create table user(id int,name varchar(20))' ) value = [,'jkmiao']
cur.execute("insert into user values(%s,%s)",value) users = [] for i in range():
users.append((i,"user"+str(i))) cur.executemany("insert into user values(%s,%s)",users) cur.execute("update user set name="test" where id=2") res = cur.fetchone()
print res res = cur.fetchmany()
print res print cur.fetchall() conn.commit()
cur.close()
conn.close()
cur.execute('select * from user')
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[], e.args[])

2. pandas 连接操作mysql

import pandas as pd
import MySQLdb conn = MySQLdb.connect(host="localhot",user="root",passwd="*****",db="test",charset="utf8") # read
sql = "select * from user limit 3"
df = pd.read_sql(sql,conn,index_col="id")
print df # write
cur = conn.cursor()
cur.execute("drop table if exists user")
cur.execute('create table user(id int,name varchar(20))' )
pd.io.sql.write_frame(df,"user",conn)

python&pandas 与mysql 连接的更多相关文章

  1. python & pandas链接mysql数据库

    Python&pandas与mysql连接 1.python 与mysql 连接及操作,直接上代码,简单直接高效: import MySQLdb try: conn = MySQLdb.con ...

  2. python中实现mysql连接池

    python中实现mysql连接池 import pymysql from DBUtils.PooledDB import PooledDB MYSQL_HOST = 'localhost' USER ...

  3. Python pandas ERROR 2006 (HY000): MySQL server has gone away

    之前在做python pandas大数据分析的时候,在将分析后的数据存入mysql的时候报ERROR 2006 (HY000): MySQL server has gone away 原因分析:在对百 ...

  4. Python(Django) 连接MySQL(Mac环境)

    看django的文档,详细的一塌糊涂,这对文档来时倒是好事,可是数据库连接你别一带而过啊.感觉什么都想说又啥都没说明白,最有用的一句就是推荐mysqlclient.展开一个Django项目首先就是成功 ...

  5. python学习之 -mysql 连接和db_config配置

    最近学习python,记录下自己写学习python的代码和心得,自己写了一个使用python mysql 的查询语句和做的一个db_config.py 配置信息. 1.db_config.py 配置文 ...

  6. python在windows下连接mysql数据库

    一,安装MySQL-python python 连接mysql数据库需要 Python interface to Mysql包,包名为 MySQL-python ,PyPI上现在到了1.2.5版本.M ...

  7. python 和 mysql连接

    python 和 mysql连接 虫师教程:http://www.cnblogs.com/fnng/p/3565912.html 其他教程pymysql:http://www.cnblogs.com/ ...

  8. Python中操作mysql的pymysql模块详解

    Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...

  9. python针对于mysql的增删改查

    无论是BS还是CS得项目,没有数据库是不行的. 本文是对python对mysql的操作的总结.适合有一定基础的开发者,最好是按部就班学习的人阅读.因为我认为人生不能永远都是从零开始,那简直就是灾难. ...

随机推荐

  1. Centos7 安装 MySQL5.7

    Centos7 安装 MySQL5.7 一.环境介绍 1.安装包版本介绍 MySQL 有三种安装方式:RPM安装.二进制包安装.源码包安装.我们这篇文章以二进制方式安装MySQL 软件名称 版本 系统 ...

  2. [转]一种让超大banner图片不拉伸、全屏宽、居中显示的方法

    现在很多网站的Banner图片都是全屏宽度的,这样的网站看起来显得很大气.这种Banner一般都是做一张很大的图片,然后在不同分辨率下都是显示图片的中间部分.实现方法如下: <html> ...

  3. android系列9.LinearLayout学习

    <!-- <LinearLayout> 线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的 --> <LinearLayout xmlns:android=& ...

  4. Object Tracking Benchmark

    Abstract 问题: 1)evaluation is often not suffcient 2)biased for certain types of algorthms 3)datasets ...

  5. can-utils源码解析cansend

    前言 本文主要介绍socketCan中的发送函数cansend的源码解析. 代码 /* * cansend.c - simple command line tool to send CAN-frame ...

  6. ACM 常见词汇

    rectangular 美:  [rek'tæŋɡjələr] 英:  [rek'tæŋɡjʊlə(r)] adj. 矩形的:成直角的   grid 美:  [ɡrɪd] 英:  [ɡrɪd] n. ...

  7. 安卓手机文件管理器简单横向评比 - imsoft.cnblogs

      X-plore文件管理器 个人评价:安卓手机上管理文件的神器,所有文件一览无余,加上自己对软件常用功能的配置,管理文件无比方便.(本人一直使用)   Solid文件管理器 个人评价:用户体验真的很 ...

  8. CodeForces - 325E:The Red Button (哈密尔顿 转 欧拉回路)

    Piegirl found the red button. You have one last chance to change the inevitable end. The circuit und ...

  9. js操作cookie总结 及乱码

    涉及到cookie的 setPath问题: https://blog.csdn.net/damys/article/details/49737905 cookie注解:public voic getx ...

  10. 【MVC】使用MvcPager进行分页

    1.添加引用: mvcPager 版本高的提供的功能也更多. 注:下载了第一个,但是里面的一些字段是只读的.(eg:PagedList<T> .TotalItemCount)这是不符合的. ...