温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python 插入mysql数据库数据

发布时间:2020-07-26 20:44:19 来源:网络 阅读:993 作者:yzy121403725 栏目:数据库

建立数据库连接

def create_db_connect():    """    brief info for: create_db_connect         建立数据库链接          Args:          Return:          Raise:    """    conn = MySQLdb.connect(host = "rm-uf6wz3f7kb8sx983zo.mysql.rds.aliyuncs.com",                             user = "pv_cms",                             passwd = "pv_cms@123",                             port = 3306,                             charset = "utf8",                             db = "pv_interaction_bigdata")    

      return conn

插入数据:

def insert_to_info(conn):    cursor = conn.cursor()    sql = '''insert into info values(%s,%s)'''    l = [['liza','mary'],['dh','lxy']]#必须是list    cursor.executemany(sql,l)#执行多条插入数据操作    conn.commit()# 不执行不能插入数据    conn.close()

def insert_into_info(conn):    cursor = conn.cursor()    sql = '''insert into info values(%s,%s)'''    l = ('lisa','mary')#必须是tuple    cursor.execute(sql,l)#插入数据操作    conn.commit()# 不执行不能插入数据    conn.close()

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI