import pymysql cnn =pymysql.connect(host="localhost", user="root",password="1234567",database="test",charset="utf8") cursor=cnn.cursor() res =cursor.execute("select * from contacts;") print("{} rows in set.".format(res)) cursor.close() cnn.close()