- 论坛徽章:
- 0
|
1。安装mysql_python
$ tar xfz MySQL-python-1.0.0.tar.gz
$ cd MySQL-python-1.0.0
$ export mysqlversion="4.0.20"
$ export mysqlclient="mysqlclient_r"
$ export mysqloptlibs="ssl crypto"
$ python setup.py build
$ su
# python setup.py install
2。Mysql样例程序
- #!/usr/bin/env python
- import MySQLdb
- db=MySQLdb.connect(user="root",passwd="123456",db="test")
- curr=db.cursor()
- max_price=5
- curr.execute("""SELECT name, passwd FROM user WHERE id < %s""", (max_price,))
- rows=curr.fetchone()
- print rows[0]
- print rows[1]
- curr.execute('insert into user (name,passwd) values(%s,\'12345\')',(max_price))
- print curr.insert_id()
- curr.execute('delete from user where id=%s',(max_price))
复制代码 |
|