天道酬勤,学无止境

mysql-connector-python

I get NotImplementedError when trying to do a prepared statement with mysql python connector

I want to use prepared statements to insert data into a MySQL DB (version 5.7) using python, but I keep getting a NotImplementedError. I'm following the documentation here: https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursorprepared.html Using Python 2.7 and version 8.0.11 of mysql-connector-python library: pip show mysql-connector-python --- Metadata-Version: 2.1 Name: mysql-connector-python Version: 8.0.11 Summary: MySQL driver written in Python Home-page: http://dev.mysql.com/doc/connector-python/en/index.html This is a cleaned version (no specific hostname

2021-07-13 11:45:46    分类:问答    python   mysql   mysql-connector-python

Avoid 'MySQLConverter' object has no attribute '_timestamp_to_mysql' error with datetime64[ns] and MySQL

I'm reading a CSV file like this Date,Open,High,Low,Close,Volume,Adj Close 2000-12-29,30.88,31.31,28.69,29.06,31702200,27.57 2000-12-28,30.56,31.62,30.38,31.06,25053600,29.46 2000-12-27,30.38,31.06,29.38,30.69,26437500,29.11 2000-12-26,31.50,32.19,30.00,30.94,20589500,29.34 2000-12-22,30.38,31.98,30.00,31.88,35568200,30.23 2000-12-21,27.81,30.25,27.31,29.50,46719700,27.98 2000-12-20,28.06,29.81,27.50,28.50,54440500,27.03 2000-12-19,31.81,33.12,30.12,30.62,58653700,29.05 ... 2000-01-13,108.50,109.88,103.50,105.06,55779200,24.91 2000-01-12,112.25,112.25,103.69,105.62,83443600,25.05 2000-01-11

2021-06-26 21:24:21    分类:问答    mysql   numpy   pandas   sqlalchemy   mysql-connector-python

MySQLConverter' 对象没有属性 '_tuple_to_mysql' 异常与 mysql-connector(MySQLConverter' object has no attribute '_tuple_to_mysql' exception with mysql-connector)

问题 我有 8 种数据,我想通过 mysql-connector 使用 python 插入到 mysql 表中。 我查看了一些文档,说在使用 mysql-connector 时最好使用int、string 或 tuple 。 我曾尝试将某些数据类型调整为字符串或元组,但 IDE 一直显示错误......如果有人帮助我澄清我将使用哪种数据类型。 数据结构设置如下(如果有什么更好的改变,请告诉我): +----------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+---------------+------+-----+---------+-------+ | URL | varchar(1023) | YES | | NULL | | | Title | varchar(1023) | YES | | NULL | | | Content | varchar(1023) | YES | | NULL | | | Month | varchar(1023) | YES | | NULL | | | Date | varchar(1023) | YES | | NULL | | | Year | varchar

2021-06-23 20:27:18    分类:技术分享    python   mysql   types   mysql-connector-python

mysql-connector-python、mysql-connector-python-rf 和 mysql-connector-repackaged 之间有什么区别?(What are the differences between mysql-connector-python, mysql-connector-python-rf and mysql-connector-repackaged?)

问题 我想使用 python 3 的mysql-connector库。我可以使用pymysql ,但mysql-connector已经有一个连接池实现,而pymysql似乎没有。 所以这对我来说编写的代码更少。 但是,当我这样做时 $ pip3 search mysql-connector 我发现这 3 个库可用: mysql-connector-repackaged - MySQL driver written in Python mysql-connector-python-rf - MySQL driver written in Python mysql-connector-python - MySQL driver written in Python 这是非常令人困惑的。 有谁知道我应该使用哪一种,为什么? 谢谢你的帮助。 回答1 我只是问自己类似的问题,我想我找到了“新鲜”的答案。 这是两周前的信息:https://github.com/pypa/warehouse/issues/5537 似乎目前长期不活跃的人是 mysql-connector 名称的所有者,因此 MySQL 开发人员以 mysql-connector-python 的名称发布。 回答2 它们之间的主要区别是: mysql-connector-repackaged: 旧了,不要用 mysql

2021-06-23 06:37:16    分类:技术分享    python   mysql   python-3.x   pip   mysql-connector-python

Why unexpected keyword 'multi' in Python's MySQLdb module?

I am trying to delete a record in database using MySQLdb module. In https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html, I found multi=True for executing multiple queries in execution but it generates error. Can someone help me knowing that what I am missing? query = "DELETE FROM Service_Machine WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" \ "DELETE FROM Machine_Usage WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" \ "DELETE FROM Machines WHERE Id="+id+"); print(query) self.cursor.execute(query, multi=True)

2021-06-11 15:18:11    分类:问答    python   mysql-connector-python

Python mySQL 更新,工作但不更新表(Python mySQL Update, Working but not updating table)

问题 我有一个需要更新 mysql 数据库的 python 脚本,到目前为止: dbb = MySQLdb.connect(host="localhost", user="user", passwd="pass", db="database") try: curb = dbb.cursor() curb.execute ("UPDATE RadioGroups SET CurrentState=1 WHERE RadioID=11") print "Row(s) were updated :" + str(curb.rowcount) curb.close() except MySQLdb.Error, e: print "query failed<br/>" print e 脚本打印Row(s) were updated : RadioID Row(s) were updated :具有RadioID为 11 的正确行数。如果我将RadioID更改为表中不存在的另一个数字,它会说Row(s) were updated :0 RadioID Row(s) were updated :0 。 但是数据库实际上并没有更新。 CurrentState字段保持不变。 如果我将 SQL 语句复制并粘贴到 PHPMyAdmin 中,它就可以正常工作。 回答1 用 dbb.commit() 后

2021-06-09 20:46:15    分类:技术分享    python   mysql   sql-update   mysql-connector-python

Unable to use None (NULL) values in python mysql.connector in prepared INSERT statement

When trying to use prepared cursor and insert NULL values the mysql.connector reports an error: mysql.Error: 1210 (HY000): Incorrect arguments to mysqld_stmt_execute Here is a code that shows this exactly. from __future__ import print_function import mysql.connector def execsql(cursor, sqlstmt): try: cursor.execute(sqlstmt) except mysql.connector.Error as e: print("mysql.Error: %s" % e) print(cursor._executed, '\n') def execsqlwithparams(cursor, sqlstmt, params): try: cursor.execute(sqlstmt, params) except mysql.connector.Error as e: print("mysql.Error: %s" % e) print(cursor._executed, "params

2021-06-05 08:55:05    分类:问答    python   mysql   mysql-connector-python

cursor() raise errors.OperationalError(“MySQL Connection not available.”) OperationalError: MySQL Connection not available

import requests import time import csv import ast import sys import mysql.connector config = { 'user': 'root', 'password': 'password', 'host': '127.0.0.1', 'port': '3306', 'database': 'dbname', 'raise_on_warnings': True,} cnx = mysql.connector.connect(config) cursor = cnx.cursor() Running gives: Traceback (most recent call last): File "/home/ubuntu/scrapers/xrp2.py", line 17, in <module> cursor = cnx.cursor() File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 1383, in cursor raise errors.OperationalError("MySQL Connection not available.") OperationalError: MySQL

2021-06-02 14:13:32    分类:问答    python   mysql-connector   mysql-connector-python

What are the differences between mysql-connector-python, mysql-connector-python-rf and mysql-connector-repackaged?

I'd like to use the mysql-connector library for python 3. I could use pymysql instead, but mysql-connector already has a connection pool implementation, while pymysql doesn't seem to have one. So this would be less code for me to write. However, when I do $ pip3 search mysql-connector I find that these 3 libraries are available: mysql-connector-repackaged - MySQL driver written in Python mysql-connector-python-rf - MySQL driver written in Python mysql-connector-python - MySQL driver written in Python This is very confusing. Anybody knows which one I should use and why? Thanks for your help.

2021-05-25 12:55:59    分类:问答    python   mysql   python-3.x   pip   mysql-connector-python

适用于python 2的mysql。7说未找到Python v2.7(mysql for python 2. 7 says Python v2.7 not found)

问题 我已经从MySQL网站下载了mysql-connector-python-1.0.7-py2.7.msi并尝试安装,但是它给出了错误 找不到Python v2.7。 我们仅支持来自python.org的Microsoft Windows Installer(MSI)。 我在Windows XP SP3和MySQL essentials5.1.66上使用Official Python v 2.7.3 需要帮忙 ??? 回答1 在安装mysql-connector-python-1.0.7-py2.7.msi和mysql-connector-python-1.0.7-py3.2.msi时,我在Windows 7下遇到了类似的问题。 在为Windows安装Python时从"Install only for yourself"更改为"Install only for yourself" "Install for all users"安装"Install for all users" , "python 3.2 not found"问题消失,并且成功安装了mysql-connector-python-1.0.7-py3.2.msi 。 我猜是问题在于mysql连接器安装程序仅查找HKEY_LOCAL_MACHINE条目,并且它查找的内容可能在HKEY_CURRENT_USER等下

2021-05-17 16:32:55    分类:技术分享    python   mysql   python-2.7   mysql-connector-python