Python处理mysql数据库
1、检查用户环境:已经安装mysql-server,已经安装python-mysqldb 组件
        aptitude show mysql-server; aptitude show python-mysqldb

2、创建数据库,创建表,添加数据,修改mysql数据库的密码为Oracle11g

       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()

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

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

相关文章:

  • 2021-11-22
  • 2021-12-20
  • 2021-09-15
  • 2022-03-08
  • 2022-12-23
  • 2021-12-06
  • 2021-05-19
猜你喜欢
  • 2022-12-23
  • 2021-12-14
  • 2021-09-02
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案