zoukankan      html  css  js  c++  java
  • python体验(06)Python处理mysql数据库

    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

  • 相关阅读:
    创建错误日志到文件 kiddy
    简单js时钟 kiddy
    Jquery表单验证
    js 地址栏操作
    $().each和$.each的区别
    Ajax与JSON的一些总结
    分页存储过程
    CKeditor 配置使用
    ISAPI_rewrite中文手册
    js向上无缝滚动,网站公告效果
  • 原文地址:https://www.cnblogs.com/flaaash/p/1894570.html
Copyright © 2011-2022 走看看