python连接mysql数据库
# 安装 pip install pymysql # 连接数据库 connect = pymysql.connect( host='ip', port=port, user='root', passwd='password', db='db_name', charset='utf8') # 创建游标对象 cursor = connect.cursor() # sql sql_data = 'sql语句' # 提交 cursor.execute(sql_data) # 返回单个元组, 如果没有则返回 null result_data = cursor.fetchone() # 返回多个元组, 如果没有则返回 () result_data = cursor.fetchall() # 关闭连接 cursor.close()

浙公网安备 33010602011771号