Python处理mysql数据库
时间:2010-12-02 来源:许明会
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
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
相关阅读 更多 +