import MySQLdb as mysql# 第1步:创建MySQL数据库连接,获取连接对象conn = mysql.connect(host='47.104.31.138', port=3306,user='root', password='Luohao.618',database='hrs', charset='utf8mb4',connect_timeout=3)try:# 第2步:基于连接对象创建游标对象with conn.cursor(mysql.cursors.DictCursor) as cursor:# 第3步:通过游标对象向数据库发出SQL语句并获取执行结果cursor.execute('select dno as no, dname as name, dloc as location from tb_dept')# 第4步:通过游标抓取数据# fecthone() / fecthmany(n) / fetchall()for row in cursor.fetchall():print(row)finally:# 第5步:关闭连接,释放资源conn.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。