python -- MySQLdb连接mysql数据库
2024-10-21 23:07:48
1. python安装mysql
$ pip install mysql-python
2. 数据库连接程序:
import MySQLdb
# 打开数据库连接
db = MySQLdb.connect(host="vpca-1.vm.elenet.me",port=9707, user="vpca_user",passwd="123456",db="vpca_db")
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行SQL语句
cursor.execute("SELECT * FROM tb_name limit 1;")
# 使用 fetchone() 方法获取一条数据库。
data = cursor.fetchone()
print data
# 关闭数据库连接
db.close()
最新文章
- python27 ImportError: No module named site
- c语言之【#ifdef】
- Win7上安装Linux双系统
- redis数据结构整理(二)
- 从电商平台促销活动看电商app开发趋势
- undefined reference to `pthread_create'问题解决
- NServiceBus教程-持久化
- Ubuntu14.04下中山大学锐捷上网设置
- JavaScript跨站脚本攻击
- MYSQL数据库备份与恢复
- 原生 JavaScript 代码和Jquery实现对比
- 一定要学会OutputDebugString,方便源码级调试
- nginx做反向负载均衡,后端服务器获取真实客户端ip
- SpringCloud的Hystrix(一) 一个消费者内的两个服务监控
- THUWC2019 GG记
- 我的 FPGA 学习历程(14)—— PWM 脉冲宽度调制
- protobuf是什么?
- C语言复习6_doWhile循环
- IOS Xcode编译项目-报错“ld: library not found for -XX”
- 游戏中转盘概率的算法---python实现
热门文章
- jdk锁相关
- Redis-SDS
- javascript之url转义escape()、encodeURI()和decodeURI(),ifram父子传参参数有中文时出现乱码
- redux、immutablejs和mobx性能对比(三)
- JS全国城市三级联动
- Remove Duplicates from Sorted List 去除链表中重复值节点
- Java 设计模式(三)-单例模式(Singleton Pattern)
- 安装Xcode主题
- [翻译] MGConferenceDatePicker
- django导入/导出原始数据