准备用Python写点脚本练练手,于是在Ubuntu上安装Python的MySQLdb,本以为很简单的事,没想到还碰到几个小波折,因此记录一下以备忘。首先需要安装Python-dev,否则后面编译MySQLdb的时候会报错,找不到头文件:building "_mysql" extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC
-Dversion_info=(1,2,3,"final",0) -D__version__=1.2.3
-I/u01/mysql/include/mysql -I/usr/include/python2.6 -c _mysql.c
-o build/temp.linux-i686-2.6/_mysql.o -DUNIV_LINUX
In file included from _mysql.c:29:
pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command "gcc" failed with exit status 1
sudo apt-get install python-dev其次需要先安装setuptools,否则MySQLdb无法编译ImportError: No module named setuptools
setuptools从这里下载python setup.py build
sudo python setup.py install从这里下载MySQLdb
修改site.cfg将mysql_config指向正确的位置python setup.py build
sudo python setup.py install
最后还需要安装libmysqlclient-dev,否则import模块的时候会出错ImportError: libmysqlclient_r.so.16: cannot open shared object file:
No such file or directory
sudo apt-get install libmysqlclient-dev
装完以后,来个hello world式的简单查询#!/usr/bin/env python
import MySQLdbdb=MySQLdb.connect(host="host_name",db="mysql",user="ningoo",passwd="password")
c=db.cursor()
n=c.execute("select user,host from user")
for row in c.fetchall():
for col in row:
print col
CentOS下安装gcc和启动sshUbuntu 10.10下EPSON v350扫描仪的安装相关资讯 ubuntu安装
- Linux系统教程:如何通过代理服务 (03月17日)
- MacBook Air 安装 Ubuntu 双系统 (01/27/2015 16:21:32)
- Ubuntu 12.04中安装Qt SDK 1.2.1图 (11/24/2012 13:19:21)
| - Linux系统入门教程: 当使用代理服 (11/08/2015 09:04:46)
- Ubuntu安装到移动硬盘 & grub (02/05/2014 19:52:51)
- Ubuntu 下安装字体的方法 (07/12/2012 08:56:50)
|
本文评论 查看全部评论 (1)
评论声明- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
|