CWYAlpha

Just another WordPress.com site

Thought this was cool: Python操作MySQL数据库

leave a comment »


Python中居然没有内置操纵MySQL数据库的包。

Python中操作MySQL的第三方包很多,本文使用的是MySQL-python 1.2.3。

1、下载、安装

# Download
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmysql-python%2Ffiles%2Fmysql-python%2F1.2.3%2F&ts=1339082819&use_mirror=cdnetworks-kr-1

# Decompress
tar -xzvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3

2、修改site.cfg

由于我得MySQL是编译安装的。如果你是apt或者yum安装的,直接装libdevmysql或者mysql-dev即可。

主要是mysql_config一行:

[options]
# embedded: link against the embedded server library
# threadsafe: use the threadsafe client
# static: link against a static library (probably required for embedded)

embedded = False
threadsafe = True
static = False

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/mysql/bin/mysql_config

# The Windows registry key for MySQL.
# This has to be set for Windows builds to work.
# Only change this if you have a different version.
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0

然后就可以安装了:

sudo python ./setup.py install

3、CRUD用法

待续

 

 

 

 

 
from 四号程序员四号程序员: http://www.coder4.com/archives/3398

Written by cwyalpha

六月 8, 2012 在 1:57 上午

发表在 Uncategorized

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: