import pymysql host = '192.168.27.65' port = 3306 user_name = 'root' pass_word = '52MoFang' database = 'mf_oms_product' conn = pymysql.connect(host=host, port=port, user=user_name, passwd=pass_word, database=database, cursorclass=pymysql.cursors.DictCursor) # 得到一个可以执行sql 语句的光标对象 cursor = conn.cursor() # 定于需求执行的sql sql = 'select * from mf_oms_product.price_account_subject where store_code=00182 and account_subject_code=10204' # 执行sql 语句 cursor.execute(sql) # 使用fetchone 方法执行sql 语句 one = cursor.fetchall() print(one) # 关闭光标 cursor.close() # 关闭数据库 conn.close()