zoukankan      html  css  js  c++  java
  • python------mysql API

    参考引用博客:http://www.cnblogs.com/wupeiqi/articles/5713330.html

    ifconfig是linux中用于显示或配置网络设备(网络接口卡)的命令,英文全称是network interfaces configuring。

    在winxp中没有“ifconfig”这个命令。当然就会提示“不是内部或者外部命令,也不是可运行的程序”。

    在winxp中,有个cmd下使用的命令应该是“ipconfig”。

    一. python  mysql API

     

    说明:   localhost其实就是127.0.0.1,你也可以ping一下这个地址看通不通。

                数据库默认端口,不用改;

          你的数据库名字。

     1 import pymysql
     2 # 创建连接
     3 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='*******', db='xiaolazi')
     4 # 创建游标
     5 cursor = conn.cursor()
     6 #执行SQL,并返回收影响行数
     7 # effect_row = cursor.execute("select * from student")
     8 # print(effect_row)
     9 # print(cursor.fetchone())   #取出表中数据
    10 # print("---" * 10)
    11 # print(cursor.fetchall())   #取出表中所有数据
    12 
    13 data = [
    14     (6,"yaoburan",19,"2019-01-03"),
    15 (7,"xuyuan",17,"2019-01-14"),
    16 (8,"yanyan",18,"2019-01-06"),
    17 ]
    18 
    19 cursor.executemany("insert into student (id,name,age,register_date) values(%s,%s,%s,%s)", data) #默认开启事物,得commit,即确认才真正插入到数据表中
    20 conn.commit()
    21 effect_row = cursor.execute("select * from student")
    22 print(cursor.fetchall())   #取出表中所有数据
    23 # 关闭游标
    24 cursor.close()
    25 # 关闭连接
    26 conn.close()

  • 相关阅读:
    JVM内存区域类别
    ConcurrentHashMap初探
    一张图理解RACSignal的Subscription过程
    ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
    自己写简单CoreDataManager封装对CoreData操作
    [转]layoutSubviews总结
    [转]日期格式化(yyyy-MM-dd)中,为什么 M 多大写?
    Native App执行JS
    Mac下配置Maven
    Mac OS X中配置Apache
  • 原文地址:https://www.cnblogs.com/bltstop/p/10262643.html
Copyright © 2011-2022 走看看