Use of '.format()' vs. '%s' in cursor.execute() for mysql JSON field, with Python mysql.connector,
问题 My objective is to store a JSON object into a MySQL database field of type json, using the mysql.connector library. import mysql.connector import json jsonData = json.dumps(origin_of_jsonData) cnx = mysql.connector.connect(**config_defined_elsewhere) cursor = cnx.cursor() cursor.execute('CREATE DATABASE dataBase') cnx.database = 'dataBase' cursor = cnx.cursor() cursor.execute('CREATE TABLE table (id_field INT NOT NULL, json_data_field JSON NOT NULL, PRIMARY KEY (id_field))') Now, the code