老师,SELECT *不是查询全表吗,为什么只显示表的第一行数据?
来源:3-2 python链接mysql数据库
何永灿
2018-04-27
import MySQLdb
conn = MySQLdb.connect(
host = '127.0.0.1',
user = 'root',
passwd = '',
db = 'news',
port = 3
charset = 'utf8'
)
cursor_ = conn.cursor()
cursor_.execute('SELECT * FROM `news`;')
rest = cursor_.fetchone()
print(rest)
conn.close()
写回答
1回答
-
fetchone就是只查一条,你要fetchall
012018-04-27
Python操作三大主流数据库-MySQL+MongoDB+Redis
一次实战同时掌握Python操作MySQL,MongoDB,Redis 三大数据库使用技巧
2024 学习 · 376 问题
相似问题