假设您正在使用
mysql.connector(我想是),请定义自己的转换器类:
class NumpyMySQLConverter(mysql.connector.conversion.MySQLConverter): """ A mysql.connector Converter that handles Numpy types """ def _float32_to_mysql(self, value): return float(value) def _float64_to_mysql(self, value): return float(value) def _int32_to_mysql(self, value): return int(value) def _int64_to_mysql(self, value): return int(value)config = { 'user' : 'user', 'host' : 'localhost', 'password': 'xxx', 'database': 'db1'}conn = mysql.connector.connect(**config)conn.set_converter_class(NumpyMySQLConverter)


