mysql python中的pymysql模块使用
2024-08-24 05:18:23
import pymysql # 在这之前需要给mysql授登录权限 grant all on "." to 'root'@'%' identified by ""; 否则会导致连接时出错
# flush privileges;
#创建连接
conn = pymysql.connect(host='127.0.0.1',port=,user='root',passwd='',db='test') #创建游标
cursor = conn.cursor() #执行MySQL语句
SQL_core = "select * from student" # 执行MYSQL 并且返回影响行数
effect_row = cursor.execute(SQL_core)
print(effect_row) #取出数据的话 cursor.fetchone() cursor.fetchall()
print(cursor.fetchall()) data = [
(, 'c'),
(, 'd')
]
#data 两条数据一次性插入
cursor.executemany("insert into student (id, name) values(%s,%s)" ,data) #提交, 不然无法保存或者修改的数据
conn.commit() #g关闭数据连接
conn.close()
最新文章
- 50个新的汉化Demo!纯前端 Wijmo 放大招
- c# TimeSpan
- Delphi Berlin 10.1 for iOS 成生 info.plist 顺序改变了
- N900快捷键
- javaScript一些函数--Math()
- 黄聪:WordPress 多站点建站教程(五):获取子站点用户信息(通过输入站点ID号来获取该站点的所有用户)
- PHP函数补完:preg_match()
- JENKINS的远程API调用,然后用PYTHON解析出最新的版本及稳定成功的版本
- sqlserver编程基本语法
- Js-Html 前端系列--页面撑开头尾
- Java中的i=i++
- Python_ jiba、snownlp中文分词、pypinyin中文转拼音
- nginx warn an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/ while reading upstream
- M - COURSES
- @Autowired Map<;String , Object>; xx
- 尚硅谷springboot学习19-日志切换
- [Docker] Getting Started with Container Networks
- AssetBundle中Unload()方法的作用
- 安装django 提示ImportError: No module named setuptools
- java中抽象类跟接口的区别