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

  • 相关阅读:
    Linux文件系统介绍
    httpd 2.4连接php-fpm
    基于lnmp环境安装Discuz
    apache 与 php-fpm 几种处理方式
    Discuz!安装搭建
    Linux中实现文本过滤
    httpd-2.4安装配置
    firewall-cmd.man
    了解JSON
    JSTL和EL表达式
  • 原文地址:https://www.cnblogs.com/flaaash/p/1894570.html
Copyright © 2011-2022 走看看