网络编程
位置:首页>> 网络编程>> 数据库>> Python处理mysql数据库

Python处理mysql数据库

 来源:站长家园 发布时间:2010-12-03 16:23:00 

标签:python,mysql

 use mysql;
        update user set password=password('Oracle11g') where user='root';
        flush privileges;
        ---------------------
        create database myfamily;
        use myfamily;
        create table people(id int, name varchar(30), age int, sex char(1));
        insert into people values(0,'Zihao Xu',5,'M');
        select * from people;exit;3、编写pyMysql.py测试程序


phoenix@debian:~$ cat pyMysql.py
#!/usr/bin/python
#filename:pyMysql.py
#coding:utf-8

import MySQLdb
conn = MySQLdb.connect(host='127.0.0.1', db='myfamily',
        user='root', passwd='Oracle11g')
cur = conn.cursor()

r = cur.execute('insert into people values(6,\'Bill Gates\',58,\'M\')')
cur.execute('delete from people where age=58')
conn.commit()

r = cur.execute('select * from people')
r = cur.fetchall()
print r

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com