import pymysql.cursors # Connect to the database connection = pymysql.connect(host='127.0.0.1', user='root', database='', port=3306, cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: # Create a new record sql = "INSERT INTO cpu_usage VALUES ('2020-06-11 11:23:11Z', 80);" cursor.execute(sql) with connection.cursor() as cursor: # Read a single record sql = "SELECT * FROM cpu_usage;" cursor.execute(sql) result = cursor.fetchall() print(result)