要先安一个包才能使用QtSql
通过新立得安装
import PyQt5.QtSql as sql db=sql.QSqlDatabase.addDatabase('QMYSQL') db.setDatabaseName('test1') db.setUserName('root') db.setPassword('123') db.open() query=sql.QSqlQuery('select * from a1') query.first() for i in range(query.size()): print(query.value(0),query.value(1)) query.next()
db.close()