Python处理mysql数据库

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

 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

标签:python,mysql
0
投稿

猜你喜欢

  • CSS浏览器兼容方案

    2008-06-10 12:21:00
  • Python编程中运用闭包时所需要注意的一些地方

    2021-10-27 06:07:21
  • Django中传递参数到URLconf的视图函数中的方法

    2021-09-16 23:46:33
  • java使用正则表达式判断邮箱格式是否正确的方法

    2022-07-24 20:31:10
  • 如何基于Python实现电子邮件的发送

    2022-03-16 11:49:16
  • 最新anaconda安装配置教程

    2021-07-17 05:05:34
  • Python turtle库绘制菱形的3种方式小结

    2022-04-10 14:08:19
  • Python基础之dict和set的使用详解

    2022-01-16 04:15:08
  • sql 取两值之间的数据方法(例:100-200之间的数据)

    2024-01-24 03:55:20
  • ASP向SQL语句传递参数方法

    2008-04-13 06:07:00
  • Python数据结构之链表详解

    2023-07-21 04:16:19
  • Python中一般处理中文的几种方法

    2023-10-11 01:45:23
  • javascript实现延时显示提示框效果

    2024-04-25 13:10:42
  • golang操作rocketmq的示例代码

    2024-04-26 17:25:41
  • jquery实现标签上移、下移、置顶

    2024-04-19 10:17:30
  • 关于搜索建议的两点小问题

    2011-09-16 20:15:29
  • SQLServer 全文检索(full-text)语法

    2011-12-01 10:38:22
  • oracle 函数

    2010-07-23 13:06:00
  • SQL SERVER 2008 CTE生成结点的FullPath

    2024-01-16 08:04:29
  • 详解SQL Server中的事务与锁问题

    2024-01-12 16:26:12
  • asp之家 网络编程 m.aspxhome.com