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

  • 相关阅读:
    excel转换为dta格式
    移动pdf
    豆瓣爬虫
    python给证件照换底色
    OS模块
    决策树参数
    Pandas数据连接
    Sklearn用法
    numpy.loadtxt()用法
    单片机基础(五):定时/计数器的工作原理及工作方式
  • 原文地址:https://www.cnblogs.com/flaaash/p/1894570.html
Copyright © 2011-2022 走看看