ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

python3 MySQL数据库的操作

2022-08-29 15:31:28  阅读:70  来源: 互联网

标签:数据库 cursor location 提交 MySQL document python3 user


导入MySQL驱动:
import mysql.connector
conn = mysql.connector.connect(user='root',password='000000',database='test')
cursor = conn.cursor()
cursor.execute('create table user (id varchar(20) primary key, name varchar(20))')      # 创建user表
cursor.execute('insert into user (id, name) values (%s, %s)', ['1', 'Michael'])     # 插入一行记录,注意MySQL的占位符是%s:
cursor.rowcount      # 显示插入的数据量
conn.commit()        # 提交事务
cursor.close()       # 关闭Cursor

 

 

# 提交事务# 提交事务# 提交事务 TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
  TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back

标签:数据库,cursor,location,提交,MySQL,document,python3,user
来源: https://www.cnblogs.com/frank1/p/16636064.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有