1.下载python
wget
2.下载mysqldb模块
wget
tar -zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
ImportError: No module named setuptools
3.下载setuptools模块
wget
tar -zxvf setuptools-0.6c8.tar.gz
cd setuptools-0.6c8
python setup.py install
cd ../MySQL-python-1.2.3
python setup.py install
4.测试
>>> import MySQLdb
-----------------------------------------------------------------------------
#!/usr/local/bin/python
#mysql connect
import MySQLdb
import sys
try:
conn=MySQLdb.connect(host="127.0.0.1",port=3306,user="root",passwd="",db="ultrax")
except MySQLdb.Error,e:
print "Error %d: %s" %(e.args[0],e.args[1])
sys.exit(1)
string=" select * from pre_common_admincp_group limit 5;"
cursor=conn.cursor()
cursor.execute(string)
result=cursor.fetchall()
for row in result:
print row
conn.close
-------------------------------------------------------------------
[root@localhost python]# ./mysql-ex1.py
(1, '\xe9\x97\xa8\xe6\x88\xb7\xe7\xae\xa1\xe7\x90\x86\xe5\x91\x98')
(2, '\xe5\xb9\xbf\xe5\x9c\xba\xe7\xae\xa1\xe7\x90\x86\xe5\x91\x98')
(3, '\xe7\xbe\xa4\xe7\xbb\x84\xe7\xae\xa1\xe7\x90\x86\xe5\x91\x98')
(4, '\xe7\xa9\xba\xe9\x97\xb4\xe7\xae\xa1\xe7\x90\x86\xe5\x91\x98')
(5, '\xe7\x94\xa8\xe6\x88\xb7\xe7\xae\xa1\xe7\x90\x86\xe5\x91\x98')
阅读(546) | 评论(0) | 转发(0) |