mysql-connector-python

Properly getting blobs from mysql database with mysql connector in python

三世轮回 提交于 2020-05-13 14:48:06
问题 When executing the following code: import mysql.connector connection = mysql.connector.connect(...) # connection params here cursor = connection.cursor() cursor.execute('create table test_table(value blob)') cursor.execute('insert into test_table values (_binary %s)', (np.random.sample(10000).astype('float').tobytes(),)) cursor.execute('select * from test_table') cursor.fetchall() I get the following error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf7 in position 1: invalid start

MySQL Connector could not process parameters

女生的网名这么多〃 提交于 2020-04-28 19:31:54
问题 I'm trying to loop through an array and insert each element into a table. As far as I can see my syntax is correct and I took this code straight from Microsoft Azure's documentation. try: conn = mysql.connector.connect(**config) print("Connection established") except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with the user name or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print

Why mysql.connector works without problem with python2.7 and not with python3?

蓝咒 提交于 2020-04-18 05:45:35
问题 I checked different post like: Is there a way to use 'pool_reset_connection' from mysql-connector-python with MariaDB 10.4.7? But I can't solve my isue, I have a program write in python 2.7; now I'm moving everything to python 3 but I got problems with mysql.connector. In this moment I'm using python 3.8.2 and mysql-connector-python==8.0.19 but I try with different version of python 3, but I was getting always the same error on mysql.connector when I try to close the connection. Traceback

Python: ImportError no module named mysql.connector

本小妞迷上赌 提交于 2020-01-30 08:11:07
问题 I just created an exe from python script and when I tried to run it, it did not show up. Then, I tried to run it from cmd and I got ImportError below: Traceback (most recent call last): File "tkintertest2.py", line 17, in <module> File "Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module File "MySQL.py", line 1, in <module> ImportError: No module named mysql.connector Failed to execute script tkintertest2 How to solve this? I have installed mysql.connector

MySQL Connector for Python

a 夏天 提交于 2020-01-06 07:29:09
问题 I am using mysql.connector for Python. Below are my connection parameters. How can I set a timeout or increase the default timeout? class Config(object): """Configure me so examples work Use me like this: mysql.connector.Connect(**Config.dbinfo()) """ HOST = dbhost DATABASE = dbdatabase USER = dbusername PASSWORD = dbpassword PORT = 3306 CHARSET = 'utf8' UNICODE = True WARNINGS = True @classmethod def dbinfo(cls): return { 'host': cls.HOST, 'port': cls.PORT, 'database': cls.DATABASE, 'user':

Python hangs on fetchall using MySQL connector

帅比萌擦擦* 提交于 2020-01-04 17:52:28
问题 I am fairly new to Python and MySQL. I am writing code that queries 60 different tables each containing records for each second in a five minute period. The code executes every five minutes. A few of the queries can reach 1/2 MB of data but most are in the 50 KB range. I am running on a workstation running Windows 7,64-bit using MySQL Connector/Python. I am testing my code using PowerShell windows but the code will eventually run as a scheduled task. The workstation has plenty of RAM (8 GB).

Python hangs on fetchall using MySQL connector

浪子不回头ぞ 提交于 2020-01-04 17:52:22
问题 I am fairly new to Python and MySQL. I am writing code that queries 60 different tables each containing records for each second in a five minute period. The code executes every five minutes. A few of the queries can reach 1/2 MB of data but most are in the 50 KB range. I am running on a workstation running Windows 7,64-bit using MySQL Connector/Python. I am testing my code using PowerShell windows but the code will eventually run as a scheduled task. The workstation has plenty of RAM (8 GB).

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

故事扮演 提交于 2020-01-02 09:19:19
问题 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

MySQL Connector/Python - insert python variable to MySQL table

一笑奈何 提交于 2019-12-29 06:53:51
问题 I'm trying to insert a python variable into a MySQL table within a python script but it is not working. Here is my code add_results=("INSERT INTO account_cancel_predictions" "(account_id,21_day_probability,flagged)" "Values(%(account_id)s,%(21_day_probability)s,%(flagged)s)") data_result={ 'account_id':result[1,0], '21_day_probability':result[1,1], 'flagged':result[1,2] } cursor.execute(add_results,data_result) cnx.commit() cursor.close() cnx.close() This gets the error ProgrammingError:

Use parameterized query with mysql.connector in Python 2.7

混江龙づ霸主 提交于 2019-12-23 16:30:12
问题 Im using Python 2.7 with mysql.connector running in pyCharm I need to use a parameterized query like shown here and also here Given those examples, it seems like cursor.execute("SELECT * FROM automatedReports WHERE pythonFunctionName = %s", (function_name)) in the below should work. However, when I write this line in pyCharm, I get this error: The inspection says: If I run the code, I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server