|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小知识:CentOS并不是第一个提供商业支持的RHEL克隆版,其他企业例如Oracle也提供了基于RedHat的自己的企业Linux发布版。
先肯定情况能否已支撑MySQLdb模块,假如没有,存问装,以下:
[root@bw-vm-soft~]#wgethttp://jaist.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
[root@bw-vm-soft~]#tarzxvfMySQL-python-1.2.3.tar.gz
[root@bw-vm-soft~]#cdMySQL-python-1.2.3
修正site.cfg中的mysql_config路径
visite.cfg
mysql_config=/usr/local/webserver/mysql/bin/mysql_config(依据mysql装置路径而定)
[root@bw-vm-softMySQL-python-1.2.3]#pythonsetup.pybuild
[root@bw-vm-softMySQL-python-1.2.3]#pythonsetup.pyinstall
确认装置胜利后
请在/etc/ld.so.conf添加/usr/local/webserver/mysql/lib/mysql,然后履行ldconfig
以后就能够进入正题,操作/治理Mysql了
例1、拔出数据
###########################################################################
#!/usr/bin/envpython
#_*_coding:utf-8_*_
importMySQLdbasmdb
importsys
con=mdb.connect(localhost,root,123123,pythontest)
withcon:
cur=con.cursor()
cur.execute("CREATETABLEIFNOTEXISTS
Users(IdINTPRIMARYKEYAUTO_INCREMENT,NameVARCHAR(25))")
cur.execute("INSERTINTOUsers(Name)VALUES(Richardshen)")
cur.execute("INSERTINTOUsers(Name)VALUES(Zhangsan)")
cur.execute("INSERTINTOUsers(Name)VALUES(Lisi)")
cur.execute("INSERTINTOUsers(Name)VALUES(Wangdongdong)")
###########################################################################
例2、检查数据
#!/usr/bin/envpython
#_*_coding:UTF-8_*_
importMySQLdbasmdb
importsys
con=mdb.connect(localhost,root,123123,pythontest)
withcon:
cur=con.cursor()
cur.execute("SELECT*FROMUsers")
numrows=int(cur.rowcount)
foriinrange(numrows):
row=cur.fetchone()
printrow[0],row[1]
履行成果:
1Richardshen
2Zhangsan
3Lisi
4Wangdongdong
这是数据库最根本的操作
小知识:CentOS商业化干掉红帽才是出路? |
|