import mysql.connector from mysql.connector import errorcode config = { 'user': 'root', 'password': 'unJEPimbJddHP8', 'host': '127.0.0.1', 'database': 'zxdb', 'raise_on_warnings': True } try: cnx = mysql.connector.connect(**config) except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your user name or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) cursor = cnx.cursor() query = ("SELECT id, title FROM entries " "WHERE id BETWEEN %s AND %s") id_start = 1950 id_end = 1980 cursor.execute(query, (id_start, id_end)) for (id, title) in cursor: print("{} ({})".format(title, id)) cursor.close() cnx.close()