zoukankan      html  css  js  c++  java
  • python 关于mysql 的 API pymysql

    pip install pymysql    (py2 叫MySQLdb)

    import pymysql
    
    #添加数据
    
    conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='yyy')
    
    cursor = conn.cursor()
    
    
    # sql = """CREATE TABLE EMPLOYEE (
    #          FIRST_NAME  CHAR(20) NOT NULL,
    #          LAST_NAME  CHAR(20),
    #          AGE INT,
    #          SEX CHAR(1),
    #          INCOME FLOAT )"""
    # 
    # cursor.execute(sql)
    
    #row_affected = cursor.execute("create table t1(id INT ,name VARCHAR(20))")
    
    #row_affected=cursor.execute("INSERT INTO t1(id,name) values (1,'alvin'),(2,'xialv')")
    
    #cursor.execute("update t1 set name = 'silv2' where id=2")
    
    
    
    
    #查询数据
    row_affected=cursor.execute("select * from t1")
    one=cursor.fetchone()
    
    # many=cursor.fetchmany(2)
    # all=cursor.fetchall()
    
    
    
    #scroll
    #cursor.scroll(-1,mode='relative')  # 相对当前位置移动
    
    #cursor.scroll(2,mode='absolute') # 相对绝对位置移动
    
    
    #更改获取数据结果的数据类型,默认是元组,可以改为字典等:conn.cursor(cursor=pymysql.cursors.DictCursor)
    
    
    conn.commit()
    cursor.close()
    conn.close()
  • 相关阅读:
    .Net常见笔试题
    冒泡排序算法 C#版
    Bundle捆绑压缩技术
    异步Ajax
    HtmlHelper总结
    HtmlHelper的扩展分页方法
    WCF
    程序猿值得看的几个技术网站(记录)
    Struts2和SpringMVC的区别
    nginx配置文件作用介绍
  • 原文地址:https://www.cnblogs.com/dangrui0725/p/9610737.html
Copyright © 2011-2022 走看看