<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - Connector/Python</title>
        <description>Forum for Connector/Python</description>
        <link>https://forums.mysql.com/list.php?50</link>
        <lastBuildDate>Fri, 10 Apr 2026 12:39:04 +0000</lastBuildDate>
        <generator>Phorum 5.2.23</generator>
        <item>
            <guid>https://forums.mysql.com/read.php?50,740809,740809#msg-740809</guid>
            <title>Python mysql-connector not working on Windows machine (Process ended with exit code 3221225477) (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,740809,740809#msg-740809</link>
            <description><![CDATA[ I have used this library on many Windows machines and I have noticed some strange behaviour. On some Windows machines it works without any issues, while other machines are giving error Process ended with exit code 3221225477.<br />
when trying to run Python script that uses mysql-connector-python.<br />
<br />
I have simply picked up a new Desktop PC, installed Python 3.12.7 and intalled mysql-connector-python library. See the logs below:<br />
<br />
C:\Users\Testavimas&gt;python -m pip install mysql-connector-python<br />
Collecting mysql-connector-python<br />
  Using cached mysql_connector_python-9.3.0-cp312-cp312-win_amd64.whl.metadata (7.7 kB)<br />
Using cached mysql_connector_python-9.3.0-cp312-cp312-win_amd64.whl (16.4 MB)<br />
Installing collected packages: mysql-connector-python<br />
Successfully installed mysql-connector-python-9.3.0<br />
<br />
[notice] A new release of pip is available: 24.2 -&gt; 25.1.1<br />
[notice] To update, run: python.exe -m pip install --upgrade pip<br />
<br />
<br />
Then I try to run the following script:<br />
<br />
import mysql.connector<br />
import argparse<br />
import sys<br />
# --- Configuration (replace with your actual credentials) ---<br />
DB_CONFIG = {<br />
    &#039;host&#039;: &#039;test.test.lt&#039;,<br />
    &#039;user&#039;: &#039;lukas&#039;,<br />
    &#039;password&#039;: &#039;(o*5rR[test&#039;,<br />
    &#039;database&#039;: &#039;Testing&#039;,<br />
}<br />
# ------------------------------------------------------------<br />
<br />
<br />
def get_all_iccids():<br />
    &quot;&quot;&quot;Fetch all ICCIDs from the database and return them as a list.&quot;&quot;&quot;<br />
    connection = None<br />
    cursor = None<br />
    try:<br />
        connection = mysql.connector.connect(**DB_CONFIG)<br />
        cursor = connection.cursor()<br />
        cursor.execute(&quot;SELECT iccid FROM test_SIM_list&quot;)<br />
        result = cursor.fetchall()<br />
        return [row[0] for row in result]<br />
    except mysql.connector.Error as err:<br />
        print(f&quot;Database error: {err}&quot;)<br />
        return []<br />
    finally:<br />
        if cursor:<br />
            cursor.close()<br />
        if connection:<br />
            connection.close()<br />
<br />
<br />
def is_valid_iccid(iccid_to_check):<br />
    &quot;&quot;&quot;Check if the given ICCID exists in the list fetched from DB.&quot;&quot;&quot;<br />
    iccid_list = get_all_iccids()<br />
    return 1 if iccid_to_check in iccid_list else 0<br />
<br />
<br />
def main():<br />
    #parser = argparse.ArgumentParser(description=&quot;Validate ICCID against database list.&quot;)<br />
    #parser.add_argument(&quot;-iccid&quot;, required=True, help=&quot;ICCID to validate&quot;)<br />
    #args = parser.parse_args()<br />
<br />
    if is_valid_iccid(&quot;8937002230500332420&quot;):<br />
        print(&quot;ICCID is valid.&quot;)<br />
        return 1<br />
    else:<br />
        print(&quot;ICCID is not valid.&quot;)<br />
        return 0<br />
<br />
<br />
if __name__ == &quot;__main__&quot;:<br />
    result = main()<br />
    sys.exit(result)<br />
<br />
<br />
When I run it using Python IDE (Thonny), it crashes with the error:<br />
Process ended with exit code 3221225477.<br />
<br />
<br />
When I debug the code, I can see that it crashes at this line:<br />
        connection = mysql.connector.connect(**DB_CONFIG)<br />
<br />
<br />
<br />
<br />
I have tried to use pymysql just for testing and it worked without any issues.<br />
<br />
<br />
<br />
I would appreciate any kind of advice how to debug this issue, what can I check to figure out what is the root cause of this? Is this related to PC? Is this related to Windows? Is this related to mysql-connector-python?]]></description>
            <dc:creator>Lukas Petrikas</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Thu, 12 Jun 2025 08:07:44 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,740427,740427#msg-740427</guid>
            <title>Connection failed to remote MySQL Server (5 replies)</title>
            <link>https://forums.mysql.com/read.php?50,740427,740427#msg-740427</link>
            <description><![CDATA[ Hello community,<br />
<br />
I have a Python code that enables connection to a remote MySQL Server using my-connector-python 9.2.0 library. The connection works well with localhost, but fails with remote server, here&#039;s the error I get (in a tkinter.messagebox) :<br />
&quot;2002: Can&#039;t connect to local MySQL server through socket &#039;%-.100s&#039; (%s)<br />
<br />
In the host computer, the &quot;bind_address&quot; variable is set to 0.0.0.0 and MySQL Server is &quot;listenning&quot; to the TCP/IP connections in the right port. However, the client computer could not connect.<br />
<br />
Could anyone help me with this ?<br />
PS: I&#039;m working on Windows 10 Pro<br />
<br />
Thank you]]></description>
            <dc:creator>Anisse Ezzebdi</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 02 Dec 2025 19:48:29 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,739977,739977#msg-739977</guid>
            <title>Why I am unable to create connection with MySQL using python on Window 11 OS (3 replies)</title>
            <link>https://forums.mysql.com/read.php?50,739977,739977#msg-739977</link>
            <description><![CDATA[ The program terminates automatically without throwing any error or output<br />
<br />
Server is also running on port 3306. Id and pass is also correct but still no output terminal just gets closed while connecting and IDLE restarts automatically.<br />
<br />
The port and connector working fine and details are given below.<br />
<br />
C:\Users\jsr&gt;pip list<br />
Package                Version<br />
---------------------- -------<br />
mysql-connector-python 9.1.0<br />
pip                    24.3.1<br />
<br />
C:\Users\jsr&gt;netstat -an | findstr 3306<br />
  TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING<br />
  TCP    0.0.0.0:33060          0.0.0.0:0              LISTENING<br />
  TCP    [::]:3306              [::]:0                 LISTENING<br />
  TCP    [::]:33060             [::]:0                 LISTENING<br />
<br />
_________________________________<br />
<br />
Python code-<br />
<br />
import mysql.connector<br />
from mysql.connector import Error<br />
<br />
HOST = &quot;localhost&quot;<br />
PORT = 3306<br />
USER = &quot;sud0077&quot;<br />
PASSWORD = &quot;Admin@123&quot;<br />
DATABASE = &quot;QuizzApp&quot;<br />
<br />
try:<br />
    mydb = mysql.connector.connect(<br />
        user=USER,<br />
        password=PASSWORD,<br />
        host=HOST,<br />
        port=PORT,<br />
        database=DATABASE<br />
    )<br />
    if mydb.is_connected():<br />
        print(&quot;Connection successful&quot;)<br />
except Error as e:<br />
    print(f&quot;Error: {e}&quot;)<br />
finally:<br />
    try:<br />
        if mydb.is_connected():<br />
            mydb.close()<br />
            print(&quot;Connection closed&quot;)<br />
    except NameError:<br />
        print(&quot;Connection was never established&quot;)<br />
<br />
for more details I have shared i video link it will gives you clear picture that I am facing<br />
<br />
youtu.be/3vFn4vrDJEM <br />
<br />
Please help to clear this issue, I don&#039;t know how this will solve]]></description>
            <dc:creator>SUDHAKAR PATHAK</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 02 Dec 2025 20:12:58 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,739370,739370#msg-739370</guid>
            <title>MYSQL -  Python Connector - No Response (6 replies)</title>
            <link>https://forums.mysql.com/read.php?50,739370,739370#msg-739370</link>
            <description><![CDATA[ Hello,<br />
<br />
Situation<br />
I am trying to troubleshoot my issue between Python and MYSQL. I have found myself in a situation where I am temporarily forced to develop on a Windows 11 machine. I am not sure if that is why I am experiencing problems as I have never had an issue on the *NIX machine. I am using MYSQL 8.0.40 and Python 3.13 64bit natively with MYSQL-Connector-Python installed via PIP.<br />
<br />
Problem<br />
When I try to connect and create, edit, view databases or tables I get no errors but I get no action either. Basically, I have confirmed that I can connect to MYSQL from Python but it appears no SQL statements execute.<br />
<br />
Actions<br />
I installed MYSQL from the MS Installer and Python without issue. I installed the connector using pip install mysql-connector-python without problem.<br />
<br />
<br />
I am using the test example to connect to an existing DB using this:<br />
<br />
------<br />
import mysql.connector<br />
<br />
cnx = mysql.connector.connect(user=&#039;user&#039;, password=&#039;pass&#039;,<br />
                              host=&#039;localhost&#039;,<br />
                              database=&#039;testdb&#039;)<br />
<br />
cnx.close()<br />
-----------<br />
<br />
When I run the script, there are no errors so I assume it works. I experimented with changing the host using various IPs and got timeout errors back so I assume it is connecting.<br />
<br />
I then tried to create a new DB using the following:<br />
<br />
import mysql.connector<br />
<br />
----------<br />
mydb = mysql.connector.connect(<br />
  host=&quot;localhost&quot;,<br />
  user=&quot;yourusername&quot;,<br />
  password=&quot;yourpassword&quot;<br />
)<br />
<br />
mycursor = mydb.cursor()<br />
<br />
mycursor.execute(&quot;CREATE DATABASE mydatabase&quot;) <br />
<br />
--------<br />
<br />
There are no errors but no DB gets created. I&#039;ve tried this with an existing DB and created a table with no success. I have checked permissions, and I have used MYSQL root user and an admin user with full rights.<br />
<br />
Troubleshooting<br />
How can I see what is happening? For example is there a log that might explain what is happening here. Is this a common problem around permissions on Win OS? If anyone can suggest what might be happening it will be appreciated.<br />
<br />
Thank you in advance.]]></description>
            <dc:creator>Jayson Wonder</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 02 Dec 2025 19:58:02 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,729839,729839#msg-729839</guid>
            <title>help needed (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,729839,729839#msg-729839</link>
            <description><![CDATA[ A very noob question maybe sorry<br />
<br />
Why am I getting a `mysql.connector.errors.InterfaceError: 2013, &#039;Lost connection to MySQL server during query&#039; when executing large transactions?]]></description>
            <dc:creator>Charles Johnson</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Sat, 26 Oct 2024 03:57:20 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,727375,727375#msg-727375</guid>
            <title>mysql.connect kernel has died (4 replies)</title>
            <link>https://forums.mysql.com/read.php?50,727375,727375#msg-727375</link>
            <description><![CDATA[ Dear all, <br />
I am trying to connect to my database using Python commands such as:<br />
<br />
 conn= mysql.connector.connect(host=&#039;127.0.0.1&#039;,<br />
       user=&#039;root&#039;,<br />
       password=&#039;my_real_password&#039;,<br />
       database=&#039;database_name&#039;)<br />
<br />
Unfortunately, Python kernel dies and no error message pop out.<br />
<br />
Any advice would be greatly appreciated.<br />
<br />
Best !]]></description>
            <dc:creator>Quentin M</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 12 Nov 2024 21:36:25 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,725253,725253#msg-725253</guid>
            <title>[BUG] v8.2.0 breaking with ssh tunnel (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,725253,725253#msg-725253</link>
            <description><![CDATA[ Hi,<br />
<br />
Trying to run 8.2.0 of the mysql python connector with the sshtunnel package to connect to a remote server. The code is very simple and I used a new environment with bare minimum packages. It seems like 8.2.0 introduced a breaking change that makes the code hang at the mysql.connector.connect() call and times out. The same code on 8.1.0 works fine and produces the expected output.<br />
<br />
<pre class="bbcode">
from sshtunnel import SSHTunnelForwarder
import mysql.connector

# Define your SSH and database connection details
SSH_HOST = &#039;&#039;
SSH_PORT = 22
SSH_USERNAME = &#039;&#039;
SSH_PASSWORD = &#039;&#039;

DB_HOST = &#039;localhost&#039;
DB_PORT = 3306  
DB_USER = &#039;&#039;
DB_PASSWORD = &#039;&#039;

with SSHTunnelForwarder(
    (SSH_HOST, SSH_PORT),
    ssh_username=SSH_USERNAME,
    ssh_password=SSH_PASSWORD,
    remote_bind_address=(DB_HOST, DB_PORT)
) as tunnel:
    local_port = tunnel.local_bind_port

    connection = mysql.connector.connect(
        host=&#039;127.0.0.1&#039;,
        port=local_port,
        user=DB_USER,
        password=DB_PASSWORD
    )

    cursor = connection.cursor()
    cursor.execute(&quot;SHOW DATABASES&quot;)
    databases = cursor.fetchall()

    for db in databases:
        print(db[0])

    cursor.close()
    connection.close()</pre>
-----<br />
<br />
Python version 3.12.4<br />
Installed packages<br />
<br />
Package                Version<br />
---------------------- -------<br />
bcrypt                 4.2.0<br />
cffi                   1.16.0<br />
cryptography           43.0.0<br />
mysql-connector-python 8.1.0<br />
paramiko               3.4.0<br />
pip                    24.0<br />
protobuf               4.21.12<br />
pycparser              2.22<br />
PyNaCl                 1.5.0<br />
setuptools             69.5.1<br />
sshtunnel              0.4.0<br />
wheel                  0.43.0]]></description>
            <dc:creator>Philip Heurich</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Thu, 25 Jul 2024 10:53:01 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,724797,724797#msg-724797</guid>
            <title>Poll:  Anyone using c-extension? (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,724797,724797#msg-724797</link>
            <description><![CDATA[ Hey devs<br />
<br />
Can I ask if you would reply to this thread and let me know if you are. using the c-extension and, if so, why?  <br />
<br />
Thanks!]]></description>
            <dc:creator>Reggie Burnett</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Thu, 13 Jun 2024 14:51:59 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,724706,724706#msg-724706</guid>
            <title>Async connector and connection pool (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,724706,724706#msg-724706</link>
            <description><![CDATA[ Hello!<br />
I developed an application, basted on FastAPI, currently implemented using the classic blocking MySQL Python connector, which allows multiple clients to concurrently query the database.<br />
In order to improve performances with many active clients, I&#039;m using a connection pool.<br />
I would like to use the new async/await api offered by version 8.3 of the Python connector, but it seems it&#039;s lacking connection pool support.<br />
<br />
Now, my question is the following: do I really need a connection pool?]]></description>
            <dc:creator>Stefano Varesi</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Mon, 10 Jun 2024 22:37:18 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,724667,724667#msg-724667</guid>
            <title>TypeError( TypeError: Python &#039;states&#039; cannot be converted to a MySQL type (8 replies)</title>
            <link>https://forums.mysql.com/read.php?50,724667,724667#msg-724667</link>
            <description><![CDATA[ Using `mysql-connector-python` 8.4.0 with Python 3.11 and Django 4.2<br />
<br />
<br />
I have a model `Job` and when I try to create an instance, I get the following error which seems to suggest that the connector is not able to handle the Django enumeration type as described here...<br />
<br />
<a href="https://docs.djangoproject.com/en/3.2/ref/models/fields/#enumeration-types"  rel="nofollow">https://docs.djangoproject.com/en/3.2/ref/models/fields/#enumeration-types</a><br />
<br />
What am I missing?<br />
<br />
Rob<br />
<br />
```Error<br />
Traceback (most recent call last):<br />
  File &quot;/Users/robertcollins/github/mtm-crm-patch/venv11/lib/python3.11/site-packages/mysql/connector/cursor.py&quot;, line 564, in _process_params<br />
    res = [to_mysql(value) for value in res]<br />
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br />
  File &quot;/Users/robertcollins/github/mtm-crm-patch/venv11/lib/python3.11/site-packages/mysql/connector/cursor.py&quot;, line 564, in &lt;listcomp&gt;<br />
    res = [to_mysql(value) for value in res]<br />
           ^^^^^^^^^^^^^^^<br />
  File &quot;/Users/robertcollins/github/mtm-crm-patch/venv11/lib/python3.11/site-packages/mysql/connector/conversion.py&quot;, line 237, in to_mysql<br />
    raise TypeError(<br />
TypeError: Python &#039;states&#039; cannot be converted to a MySQL type<br />
```<br />
<br />
The Django Model definition is:-<br />
```<br />
class Job(models.Model):<br />
    class STATES(TextChoices):<br />
        NEW = &quot;NEW&quot;<br />
        READY = &quot;READY&quot;<br />
        PROCESSING = &quot;PROCESSING&quot;<br />
        STOPPING = &quot;STOPPING&quot;<br />
        FAILED = &quot;FAILED&quot;<br />
        COMPLETE = &quot;COMPLETE&quot;<br />
<br />
    id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)<br />
    created = models.DateTimeField(auto_now_add=True, db_index=True)<br />
    modified = models.DateTimeField(auto_now=True)<br />
    name = models.CharField(max_length=100)<br />
    state = models.CharField(<br />
        max_length=20, choices=STATES.choices, default=STATES.NEW, db_index=True<br />
    )<br />
    next_task = models.CharField(max_length=100, blank=True)<br />
    workspace = JSONField(null=True)<br />
    queue_name = models.CharField(max_length=20, default=&quot;default&quot;, db_index=True)<br />
    priority = models.SmallIntegerField(default=0, db_index=True)<br />
    run_after = models.DateTimeField(null=True, db_index=True)<br />
<br />
    class Meta:<br />
        ordering = [&quot;-priority&quot;, &quot;created&quot;]<br />
<br />
    objects = JobManager()<br />
<br />
    def save(self, *args, **kwargs):<br />
        if self._state.adding:<br />
            self.next_task = get_next_task_name(self.name)<br />
            self.workspace = self.workspace or {}<br />
<br />
            try:<br />
                self.run_creation_hook()<br />
            except Exception as exception:  # noqa<br />
                logger.exception(<br />
                    &quot;Failed to create new job, creation hook raised an exception&quot;<br />
                )<br />
                return  # cancel the save<br />
<br />
        return super().save(*args, **kwargs)<br />
<br />
    def update_next_task(self):<br />
        self.next_task = get_next_task_name(self.name, self.next_task) or &quot;&quot;<br />
<br />
    def get_failure_hook_name(self):<br />
        return get_failure_hook_name(self.name)<br />
<br />
    def get_creation_hook_name(self):<br />
        return get_creation_hook_name(self.name)<br />
<br />
    def run_creation_hook(self):<br />
        creation_hook_name = self.get_creation_hook_name()<br />
        if creation_hook_name:<br />
            logger.info(&quot;Running creation hook %s for new job&quot;, creation_hook_name)<br />
            creation_hook_function = import_string(creation_hook_name)<br />
            creation_hook_function(self)<br />
<br />
    @staticmethod<br />
    def get_queue_depths():<br />
        annotation_dicts = (<br />
            Job.objects.filter(state__in=(Job.STATES.READY, Job.STATES.NEW))<br />
            .values(&quot;queue_name&quot;)<br />
            .order_by(&quot;queue_name&quot;)<br />
            .annotate(Count(&quot;queue_name&quot;))<br />
        )<br />
<br />
        return {<br />
            annotation_dict[&quot;queue_name&quot;]: annotation_dict[&quot;queue_name__count&quot;]<br />
            for annotation_dict in annotation_dicts<br />
        }<br />
```<br />
<br />
The Job create is...<br />
```<br />
context = {<br />
                &quot;postal_code&quot;: self.applicant_postal_code,<br />
                &quot;application_id&quot;: self.id,<br />
            }<br />
            try:<br />
                Job.objects.create(<br />
                    name=&quot;locate_application_form_job&quot;,<br />
                    workspace=context,<br />
                    queue_name=&quot;mapit_queue&quot;,<br />
                )<br />
            except Exception as e:<br />
                logger.error(<br />
                    f&quot;Cannot create background locate_application_form_job for application&quot;<br />
                    f&quot;:{self.id}\n{e}&quot;<br />
                )<br />
```]]></description>
            <dc:creator>Rob Collins</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Wed, 11 Sep 2024 14:33:09 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,724451,724451#msg-724451</guid>
            <title>Slow query performance (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,724451,724451#msg-724451</link>
            <description><![CDATA[ Hi<br />
<br />
I have written a Python program to strip down a csv log file that contains every connection to our streaming server.<br />
<br />
The data is stripped from the csv log and then processed line by line and each line is stored in a table.<br />
<br />
Every time I read a line from the csv file, I check if there isn&#039;t an existing entry like this in the database to prevent duplicates.<br />
<br />
The problem I have is that the database table currently has over 1 900 000 records. I&#039;m using a select query by only selecting one column to try and optimize the query and feeding it only the necessary columns to match. I only need a row count returned.<br />
<br />
Each time I run the query, it takes about 3 to 4 seconds to return a count. Checking the CPU usage of mysql shows it maxed out to 100%<br />
<br />
A csv log file can grow as big with 4000 new lines in one hour and will expand when we have more clients.<br />
<br />
If one line takes 3 seconds to process, This means the current instance of the python program will complete over just 3 hours.<br />
<br />
To add to the problem, I have a cronjob running each hour to run the python program to strip out the past hour&#039;s entries. This will slow the system even further down as there is an existing instance running of the program.<br />
<br />
Is there any way that I can optimize the query any further or change settings in mysql or any other ways to speed up these queries?]]></description>
            <dc:creator>Claude van der Ryst</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 28 May 2024 16:56:10 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,723911,723911#msg-723911</guid>
            <title>ClientFlag MULTI_STATEMENTS (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,723911,723911#msg-723911</link>
            <description><![CDATA[ I checked documents, but can&#039;t found sample codes of executing multi statements using mysql-connector-python, so need help to correct the following.<br />
<br />
```<br />
import mysql.connector<br />
from mysql.connector import ClientFlag<br />
<br />
# Connect with the MySQL Server<br />
con = mysql.connector.connect(**CFG)<br />
con.set_client_flags([ClientFlag.MULTI_STATEMENTS])<br />
con.reconnect()<br />
<br />
cur = con.cursor()<br />
<br />
SQL = &quot;update class set age=123 where name=&#039;w1&#039;;update class set age=456 where name=&#039;w2&#039;;&quot;<br />
cur.execute(SQL)<br />
<br />
....<br />
```]]></description>
            <dc:creator>q kaiwei</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Sat, 27 Apr 2024 20:31:25 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,723625,723625#msg-723625</guid>
            <title>Python Connector gives incorrect result (2 replies)</title>
            <link>https://forums.mysql.com/read.php?50,723625,723625#msg-723625</link>
            <description><![CDATA[ This python code:<br />
<br />
```python<br />
import mysql.connector<br />
<br />
try:<br />
    conn = mysql.connector.connect(<br />
        host=&quot;localhost&quot;, user=&quot;fanw&quot;, password=&quot;secret&quot;, database=&quot;fanw&quot;<br />
    )<br />
<br />
    cursor = conn.cursor()<br />
    query = &quot;&quot;&quot;<br />
        CREATE TEMPORARY TABLE IF NOT EXISTS temp_pairs AS<br />
<br />
        SELECT<br />
            fd.nid,<br />
            fd.title<br />
        FROM<br />
            node__field_card_display cl<br />
        JOIN <br />
            node_field_data fd ON cl.entity_id = fd.nid AND cl.langcode = fd.langcode<br />
        WHERE<br />
            cl.field_card_display_target_id = 2049<br />
            AND cl.langcode = &#039;en&#039;<br />
            AND cl.bundle = &#039;person&#039;;<br />
<br />
        SELECT<br />
            t.entity_id,<br />
            t.deleted,<br />
            t.delta,<br />
            t.langcode,<br />
            t.body_value,<br />
            GROUP_CONCAT(DISTINCT tp.nid SEPARATOR &#039;,&#039;) AS nids,<br />
            GROUP_CONCAT(DISTINCT tp.title SEPARATOR &#039;,&#039;) AS titles<br />
        FROM<br />
            node__body AS t<br />
        JOIN<br />
            temp_pairs AS tp ON BINARY t.body_value LIKE CONCAT(&#039;%&#039;, tp.title, &#039;%&#039;) <br />
            AND NOT (t.body_value LIKE CONCAT(&#039;%&#039;, tp.nid, &#039;&quot;&gt;&#039;, tp.title, &#039;&lt;&#039;, &#039;%&#039;))<br />
        WHERE<br />
            t.body_format &lt;&gt; &#039;plain_text&#039;<br />
            AND t.entity_id &lt;&gt; tp.nid<br />
        GROUP BY<br />
            t.entity_id, t.langcode;<br />
    &quot;&quot;&quot;<br />
    cursor.execute(query, multi=True)<br />
    result = cursor.fetchall()<br />
    print(len(result))<br />
    conn.commit()<br />
<br />
except Exception as e:<br />
    conn.rollback()<br />
    print(f&quot;Error: {str(e)}&quot;)<br />
<br />
finally:<br />
    cursor.close()<br />
    conn.close()<br />
<br />
print(&quot;DONE!&quot;)<br />
```<br />
<br />
Gives the result: 0<br />
<br />
While running the same query directly in mysql gives: 51<br />
<br />
```sh<br />
$ cat python_query.sql <br />
CREATE TEMPORARY TABLE IF NOT EXISTS temp_pairs AS<br />
<br />
SELECT<br />
    fd.nid,<br />
    fd.title<br />
FROM<br />
    node__field_card_display cl<br />
JOIN <br />
    node_field_data fd ON cl.entity_id = fd.nid AND cl.langcode = fd.langcode<br />
WHERE<br />
    cl.field_card_display_target_id = 2049<br />
    AND cl.langcode = &#039;en&#039;<br />
    AND cl.bundle = &#039;person&#039;;<br />
<br />
SELECT<br />
    t.entity_id,<br />
    t.deleted,<br />
    t.delta,<br />
    t.langcode,<br />
    t.body_value,<br />
    GROUP_CONCAT(DISTINCT tp.nid SEPARATOR &#039;,&#039;) AS nids,<br />
    GROUP_CONCAT(DISTINCT tp.title SEPARATOR &#039;,&#039;) AS titles<br />
FROM<br />
    node__body AS t<br />
JOIN<br />
    temp_pairs AS tp ON BINARY t.body_value LIKE CONCAT(&#039;%&#039;, tp.title, &#039;%&#039;) <br />
    AND NOT (t.body_value LIKE CONCAT(&#039;%&#039;, tp.nid, &#039;&quot;&gt;&#039;, tp.title, &#039;&lt;&#039;, &#039;%&#039;))<br />
WHERE<br />
    t.body_format &lt;&gt; &#039;plain_text&#039;<br />
    AND t.entity_id &lt;&gt; tp.nid<br />
GROUP BY<br />
    t.entity_id, t.langcode;<br />
<br />
$ mysql -u fanw -p fanw &lt; python_query.sql | wc -l    <br />
Enter password: <br />
52 (first row are the column names)<br />
```<br />
<br />
```sh<br />
$ pip freeze | grep mysql<br />
mysql-connector-python==8.3.0<br />
```<br />
<br />
python version is 3.9.10<br />
<br />
And I&#039;m running this on a MacBook Pro M1 (12.7).<br />
<br />
I&#039;ve also run the query using DBeaver, and it gives the same result; 51.]]></description>
            <dc:creator>Jim Brännlund</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Wed, 12 Jun 2024 08:00:24 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,723518,723518#msg-723518</guid>
            <title>migrating multi-line SQL commands from pymysql (3 replies)</title>
            <link>https://forums.mysql.com/read.php?50,723518,723518#msg-723518</link>
            <description><![CDATA[ I&#039;ve been tasked with migrating from pymsqyl to mysql.connector . . .  we have a bunch of code that has multi-line SQL statements that don&#039;t run as expected in mysql.connector, viz. only the first command in the multi-line statement gets run . . .  Is there a best way to migrate from pymysql to mysql.connector?  I&#039;ve added `client_flags=ClientFlag.MULTI_STATEMENTS` but then I seem to need to add `while connection.next_result(): pass` after every insert/update statement that has multi-line SQL before I can do a commit.<br />
<br />
Is there a better way?]]></description>
            <dc:creator>Guy Matz</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Thu, 22 Aug 2024 05:15:22 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,723299,723299#msg-723299</guid>
            <title>MySQL Asynchronous Connectivity with MySQL Connector/Python (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,723299,723299#msg-723299</link>
            <description><![CDATA[ <a href="https://blogs.oracle.com/mysql/post/mysql-async-connectivity-with-connector-python"  rel="nofollow">https://blogs.oracle.com/mysql/post/mysql-async-connectivity-with-connector-python</a>]]></description>
            <dc:creator>Edwin Desouza</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 12 Mar 2024 22:02:25 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,715916,715916#msg-715916</guid>
            <title>Unexpected error when calling purge command via execute (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,715916,715916#msg-715916</link>
            <description><![CDATA[ Hello!  <br />
<br />
Running python3.8, mysql-connector-python 8.3.0, and mysql 8.0.35, I&#039;ve run into something that I&#039;m unsure qualifies as a bug, but at the very least I find strange behavior.<br />
<br />
I&#039;ve got some typical factory code that has 2 exactly-as-you&#039;d-expect context-manager functions, one yields a database connection and the other uses that function to yield a cursor (for context for the next part).  <br />
<br />
-----<br />
class DBConnectionFactory:<br />
    host: str<br />
    port: int<br />
    db: str<br />
    user: str<br />
    password: str<br />
<br />
    @contextlib.contextmanager<br />
    def connect(self) -&gt; Iterator[mysql.MySQLConnection]:<br />
        conn = mysql.connect(<br />
            host=self.host,<br />
            port=self.port,<br />
            db=self.db,<br />
            user=self.user,<br />
            password=self.password,<br />
        )<br />
        conn.get_warnings = True<br />
        try:<br />
            yield conn<br />
        finally:<br />
            conn.close()<br />
<br />
    @contextlib.contextmanager<br />
    def cursor(self, dictionary: bool = False) -&gt; Iterator[Cursor]:<br />
        with self.connect() as conn:<br />
            cur = conn.cursor(dictionary=dictionary)<br />
            try:<br />
                yield cur<br />
            finally:<br />
                cur.close()<br />
-----<br />
<br />
<br />
<br />
Attempting to run a PURGE BINARY LOGS command only works when run via the database connection:<br />
<br />
-----<br />
with db.connect() as conn:<br />
    conn.cmd_query(f&quot;PURGE BINARY LOGS BEFORE &#039;{start_time}&#039;;&quot;)<br />
-----<br />
<br />
<br />
Now, this is basically what the documentation dictates, but for the longest time, I was running it like this<br />
<br />
-----<br />
with db.cursor() as cur:<br />
    cur.execute(f&quot;PURGE BINARY LOGS BEFORE &#039;{start_time}&#039;;&quot;)<br />
-----<br />
<br />
because I did not understand that there was a difference at first.  The &quot;bug&quot; behavior comes in with how mysql connector handles the response from the server.  The purge command itself is run, I can validate it by listing the binary log files and asking mysql to SHOW BINARY LOGS. but the error comes in the stack trace.<br />
<br />
-----<br />
Traceback (most recent call last):<br />
  File &quot;script.py&quot;, line 193, in flush_logs<br />
    cur.execute(f&quot;PURGE BINARY LOGS BEFORE &#039;{start_time}&#039;;&quot;)<br />
  File &quot;venv/lib/python3.8/site-packages/mysql/connector/cursor.py&quot;, line 748, in execute<br />
    self._handle_result(self._connection.cmd_query(stmt))<br />
  File &quot;/venv/lib/python3.8/site-packages/mysql/connector/cursor.py&quot;, line 614, in _handle_result<br />
    self._handle_noresultset(result)<br />
  File &quot;/venv/lib/python3.8/site-packages/mysql/connector/cursor.py&quot;, line 585, in _handle_noresultset<br />
    self._handle_warnings()<br />
  File &quot;/venv/lib/python3.8/site-packages/mysql/connector/cursor.py&quot;, line 1054, in _handle_warnings<br />
    warnings.warn(err, stacklevel=4)<br />
TypeError: expected string or bytes-like object<br />
-----<br />
<br />
Best as I can tell, the warning handler for the cursor isn&#039;t prepared to handle the non-row response from the server.  I confirmed that start_time was in fact a string, as well as the entire string I was passing to execute, so I looked into the source code and confirmed it was being thrown by the library.<br />
<br />
Now, I&#039;m not entirely sure what the best approach to this is.  I&#039;m unsure if it qualifies as a bug since I&#039;m a) probably not supposed to be running the &quot;Database level commands&quot; like purge through execute and b) fully aware of the existence of cmd_query now <br />
<br />
However, it seems like the library should either a) handle the error in a more pythonic manner since both approaches to actually run the command b) not let me run the command via execute or c) not throw an error at all.<br />
<br />
I also verified that this error is only occurring after 8.0.12, as it doesn&#039;t throw an error at all with that version, but all subsequent versions throw the error.  I&#039;d be happy to file a bug request if this is considered a bug, but I figured I&#039;d check in the forums before doing anything.]]></description>
            <dc:creator>Eli Kirmayer</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 23 Jan 2024 18:28:50 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,711670,711670#msg-711670</guid>
            <title>SSL error using mysql-connector-python 8.2.0 (no replies)</title>
            <link>https://forums.mysql.com/read.php?50,711670,711670#msg-711670</link>
            <description><![CDATA[ Hello Experts, <br />
i am using a simple python script to connect to mysql PAAS instance <br />
<br />
import mysql.connector<br />
from mysql.connector import errorcode<br />
import os<br />
try : <br />
    RPA_db = mysql.connector.connect(host=&quot;xxxx.mysql.database.azure.com&quot;, user=&quot;username&quot;, <br />
             database=&quot;rpa_log&quot;,password=&quot;YYYYYY&quot;,ssl_ca=&quot;C:\\xx\\xx\\Desktop\\Data\\xxxx.crt.pem&quot;)<br />
except mysql.connector.Error as err:<br />
    print(str(err))<br />
    exit()<br />
while executing the script am getting the below error<br />
<br />
2055: Lost connection to MySQL server at xxxxxx.azure.com:3306&#039;, system error: 1 [SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:997)<br />
<br />
any help would be appriciated.]]></description>
            <dc:creator>seetharaman k</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Wed, 29 Nov 2023 09:44:46 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,710366,710366#msg-710366</guid>
            <title>How to set a driver-side query execution timeout (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,710366,710366#msg-710366</link>
            <description><![CDATA[ Hi, is there a way to set a driver-side query execution timeout? We noticed that  the MySQL JDBC driver supports setting a driver-side socket/network timeout but the MySQL Python driver does not. This is a problem for us because if the server becomes unresponsive, any queries being executed will hang indefinitely. Is there a suggested solution for this problem?]]></description>
            <dc:creator>Aaron Congo</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 06 Aug 2024 20:40:14 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,710155,710155#msg-710155</guid>
            <title>Using mysql-connector-python 8.0.33 with MySQL 8.1 (2 replies)</title>
            <link>https://forums.mysql.com/read.php?50,710155,710155#msg-710155</link>
            <description><![CDATA[ Hi,<br />
<br />
I would like to know if using mysql-connector-python 8.0.33 with MySQL 8.1 is officially supported, or if I am required to use mysql-connector-python==8.1.0.<br />
<br />
Thanks for your help.]]></description>
            <dc:creator>Andy Newman</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Wed, 11 Oct 2023 12:00:47 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,709181,709181#msg-709181</guid>
            <title>How to perform unit testing (4 replies)</title>
            <link>https://forums.mysql.com/read.php?50,709181,709181#msg-709181</link>
            <description><![CDATA[ I want to know how to execute unittests.py with my own database parameters.]]></description>
            <dc:creator>hao peng</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Fri, 09 Jun 2023 14:23:02 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,708910,708910#msg-708910</guid>
            <title>deallocating None issue with connect/disconnect (4 replies)</title>
            <link>https://forums.mysql.com/read.php?50,708910,708910#msg-708910</link>
            <description><![CDATA[ Hi all,<br />
<br />
I run into a &quot;deallocating None&quot; error, if I use connect()/disconnect():<br />
...<br />
&#039;None&#039; refcount: 4<br />
&#039;None&#039; refcount: 3<br />
&#039;None&#039; refcount: 2<br />
Fatal Python error: deallocating None<br />
Python runtime state: initialized<br />
<br />
Current thread 0x00007f9dfb640740 (most recent call first):<br />
  File &quot;test.py&quot;, line 19 in &lt;module&gt;<br />
<br />
Any ideas? Here my environment:<br />
 python: 3.8.10<br />
 OS: ubuntu 20.04<br />
 mysql-connector-python: 8.0.33<br />
<br />
Samplecode to reproduce, just replace mysql.connector.connect() parameter with matching once:<br />
 <br />
import mysql.connector<br />
from mysql.connector import Error<br />
import sys<br />
import time<br />
<br />
if __name__ == &quot;__main__&quot;:<br />
    while True:<br />
        try:<br />
            print(f&quot;&#039;None&#039; refcount: {sys.getrefcount(None)}&quot;)<br />
            connection = mysql.connector.connect(<br />
                host = host,<br />
                port = port,<br />
                user = user,<br />
                passwd = password,<br />
                database = dbname<br />
            )<br />
            connection.disconnect()<br />
            time.sleep(0.01)<br />
        except Error:<br />
            print(&quot;error&quot;)<br />
            break]]></description>
            <dc:creator>Marcel M</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Mon, 22 May 2023 19:41:02 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,708816,708816#msg-708816</guid>
            <title>Not all records - EOF deprecation / protocol.py (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,708816,708816#msg-708816</link>
            <description><![CDATA[ On larger queries - not all of the records are making it to my .fetchall() statement.<br />
<br />
I&#039;ve tracked it down to a potential issues within protocol.py, where a deprecated EOF is being detected, which stops reading in retrieved records.<br />
<br />
I&#039;ve had to comment out this section of code, and it seems to have solved my issue.  Is this a bug, or a known incompatibility?<br />
<br />
MySQL: /usr/sbin/mysqld (mysqld 5.7.41-0ubuntu0.18.04.1)<br />
Python 3.9.5<br />
MySQL Connector: mysql_connector-2.2.9-py3.9.egg-info<br />
<br />
mysql/connector/protocol.py<br />
Line 337-340<br />
          #elif eof57 and (packet[4] == 0 and packet[0] &gt; 9):<br />
                # EOF deprecation: make sure we catch it whether flag is set or not<br />
                #eof = self.parse_ok(packet)<br />
                #rowdata = None]]></description>
            <dc:creator>Mark Simon</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Fri, 21 Apr 2023 16:15:17 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,708753,708753#msg-708753</guid>
            <title>Support for protobufs 4? (3 replies)</title>
            <link>https://forums.mysql.com/read.php?50,708753,708753#msg-708753</link>
            <description><![CDATA[ The current latest version of mysql-connector-python (8.0.32) has a dependency conflict with the oldest version of google-ads (19.0.0) that works with current Google APIs (v12+).<br />
<br />
The conflict is caused by:<br />
    google-ads 19.0.0 depends on protobuf&gt;=4.21.5<br />
    mysql-connector-python 8.0.32 depends on protobuf&lt;=3.20.3 and &gt;=3.11.0<br />
<br />
<br />
Are there plans to switch to protobuf 4.21.5+ under the covers?]]></description>
            <dc:creator>Jay Howard</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Thu, 17 Aug 2023 12:29:33 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,708537,708537#msg-708537</guid>
            <title>Connection Arguments - host (2 replies)</title>
            <link>https://forums.mysql.com/read.php?50,708537,708537#msg-708537</link>
            <description><![CDATA[ Hi<br />
<br />
How to configure host argument correctly when I have SQL DB on server instance?<br />
I have configured user only for this instance.<br />
<br />
When im trying put:<br />
host=&#039;server_name\instance_name&#039;<br />
I have an error:<br />
2005 (HY000): Unknown MySQL server host &#039;server_name\instance_name&#039; (11001)<br />
<br />
When im trying put only:<br />
host=&#039;server_name&#039;<br />
I have only the information:<br />
2013 (HY000): Lost connection to MySQL server at &#039;reading initial communication packet&#039;, system error: 0<br />
<br />
Regards<br />
Mariusz]]></description>
            <dc:creator>Mariusz Zięcina</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Mon, 27 Mar 2023 13:59:28 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,708413,708413#msg-708413</guid>
            <title>Upgrade to a newer protobuf version (3 replies)</title>
            <link>https://forums.mysql.com/read.php?50,708413,708413#msg-708413</link>
            <description><![CDATA[ In Apache Airflow we have mysql-conneector-python integration that currently holds us back from upgrading to protobuf 4.<br />
<br />
Having limitation to Requires-Dist: protobuf (&lt;Requires-Dist: protobuf (&lt;=3.20.3,&gt;=3.11.0) prevents us from upgrading most of other providers - see apache/airflow#30067, Until mysql-connector-python fixes the dependency limitation, we will be forced to stop releasing the provider together with the others (it also means it will not be compatible with the other providers and newer versions of airflow when released<br />
<br />
Can you please let us know if there are plans to upgrade the mysql-connector-python python sdk to not limit the protobuf? Otherwise we will have to exclude the mysql provider and stop releasing it.<br />
<br />
Also see the devlist discussion thread I started about it (based on yandexcloud provider, but it applies to mysql too).<br />
<br />
Thanks in advance!]]></description>
            <dc:creator>Jarek Potiuk</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Fri, 21 Apr 2023 13:54:05 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,707386,707386#msg-707386</guid>
            <title>mysql.connector.errors.InterfaceError: 2003 (2 replies)</title>
            <link>https://forums.mysql.com/read.php?50,707386,707386#msg-707386</link>
            <description><![CDATA[ here is not easy to leave the code, so I post in here<br />
<a href="https://stackoverflow.com/questions/75304961/mysql-connector-errors-interfaceerror-2003"  rel="nofollow">https://stackoverflow.com/questions/75304961/mysql-connector-errors-interfaceerror-2003</a><br />
<br />
I write a .py script can extract mysql data and print it out, I want to make the html page run this script and face mysql.connector.errors.InterfaceError, but .py script individually works fine<br />
<br />
environment: I put both .py and .html in winSCP to make the page live]]></description>
            <dc:creator>yu chuang</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Wed, 05 Apr 2023 08:51:37 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,707377,707377#msg-707377</guid>
            <title>I cannot implement python along with MySQL integration (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,707377,707377#msg-707377</link>
            <description><![CDATA[ I am facing issue that I can not implement MySQL in my system what would be main reason]]></description>
            <dc:creator>Roger Carlos</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Tue, 31 Jan 2023 14:11:20 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,706600,706600#msg-706600</guid>
            <title>Problem with inserting data into MySQL (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,706600,706600#msg-706600</link>
            <description><![CDATA[ Hi<br />
I want to read the data of a sensor and transfer it to MySQL local host with &quot;mysql.connector&quot;. The problem is that it reads the data as a list containing 500 data (that is, it reads 500 to 500, not one by one). This is my code:<br />
<br />
master_data = master_task.read(number_of_samples_per_channel=500)<br />
sql = &quot;INSERT INTO vib_data2 (data) VALUES (%s)&quot;<br />
val = list(master_data, )<br />
mycursor.executemany(sql, val)<br />
mydb.commit()<br />
<br />
<br />
I got this error:<br />
&quot;Could not process parameters: float(-0.15846696725827258), it must be of type list, tuple or dict&quot;<br />
<br />
<br />
I can fix the problem with this code:<br />
<br />
for i in master_data:<br />
   sql = &quot;INSERT INTO vib_data2 (data) VALUES (%s)&quot;<br />
   val = (str(I),)<br />
   mycursor.execute(sql, val)<br />
   mydb.commit()<br />
<br />
<br />
But the code execution time is very long (more than one second) and thus some of the data is lost.<br />
Thank you for helping to correct the code]]></description>
            <dc:creator>Mohammad Mahdi</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Thu, 20 Apr 2023 09:52:22 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,706423,706423#msg-706423</guid>
            <title>OverflowError: Python int too large to convert to C long (2 replies)</title>
            <link>https://forums.mysql.com/read.php?50,706423,706423#msg-706423</link>
            <description><![CDATA[ Hi,<br />
Can someone help me with this problem?<br />
<br />
The code below I ran on python 3.9.7 with mysql-connector-python 8.0.23 has no any problem.<br />
<br />
#########################################################################<br />
import mysqlx<br />
<br />
ss = mysqlx.get_session({&#039;host&#039;:&#039;localhost&#039;, &#039;port&#039;:33060, &#039;user&#039;:&#039;root&#039;, &#039;password&#039;:&#039;xxxx&#039;})<br />
ss.drop_schema(&#039;testx&#039;)<br />
ss.create_schema(&#039;testx&#039;)<br />
<br />
db = ss.get_schema(&#039;testx&#039;)<br />
db.create_collection(&#039;test&#039;)<br />
<br />
col = db.get_collection(&#039;test&#039;)<br />
col.add({&#039;_id&#039;:&#039;test&#039;, &#039;item&#039;:2147483648}).execute() # 8.0.23 pass, but 8.0.24 ~ 8.0.30 fail<br />
#col.add({&#039;_id&#039;:&#039;test&#039;, &#039;item&#039;:2147483647}).execute() # this line is OK for any version<br />
<br />
ss.drop_schema(&#039;testx&#039;)<br />
ss.close()<br />
#########################################################################<br />
<br />
But, after I upgrading mysql-connector-python to 8.0.24 ~ 8.0.30(python version is 3.10.7),<br />
it runs fail with the following error message.<br />
<br />
-------------------------------------------------------------------------<br />
OverflowError: Python int too large to convert to C long<br />
<br />
The above exception was the direct cause of the following exception:<br />
<br />
Traceback (most recent call last):<br />
  File &quot;R:\test.py&quot;, line 12, in &lt;module&gt;<br />
    col.add({&#039;_id&#039;:&#039;test&#039;, &#039;item&#039;:2147483648}).execute() # 8.0.23 pass, but 8.0.30 fail<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\statement.py&quot;, line 711, in execute<br />
    return self._connection.send_insert(self)<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\connection.py&quot;, line 494, in wrapper<br />
    result = func(self, *args, **kwargs)<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\connection.py&quot;, line 1150, in send_insert<br />
    self.protocol.send_msg(msg_type, msg)<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\protocol.py&quot;, line 835, in send_msg<br />
    self._writer.write_message(mysqlxpb_enum(msg_type), msg)<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\protocol.py&quot;, line 268, in write_message<br />
    msg_size = msg.byte_size(msg)<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\protobuf\__init__.py&quot;, line 541, in byte_size<br />
    else len(encode_to_bytes(msg.serialize_to_string()))<br />
  File &quot;C:\Users\zmsun\AppData\Local\Programs\Python\Python310\lib\site-packages\mysqlx\protobuf\__init__.py&quot;, line 489, in serialize_to_string<br />
    return Protobuf.mysqlxpb.serialize_message(self._msg)<br />
SystemError: &lt;built-in function serialize_message&gt; returned a result with an exception set<br />
-------------------------------------------------------------------------<br />
<br />
Is there anything I can change to fix this? Thanks.]]></description>
            <dc:creator>Zhi-Ming Sun</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Sat, 08 Oct 2022 09:16:54 +0000</pubDate>
        </item>
        <item>
            <guid>https://forums.mysql.com/read.php?50,705840,705840#msg-705840</guid>
            <title>Python mysql-connector doesn&#039;t handle numpy.nan (1 reply)</title>
            <link>https://forums.mysql.com/read.php?50,705840,705840#msg-705840</link>
            <description><![CDATA[ Hi, <br />
<br />
My workflow requires that I bulk insert pandas dataframes to a mysql database.<br />
<br />
pandas uses numpy.nan to represent null values in a dataframe&#039;s float columns.<br />
Unfortunately, when converting said values to a query, the mysql-connector converts numpy.nan to a string; &#039;nan&#039;, failing to insert it to the float column in the db.<br />
<br />
I have a code workaround where I replace all numpy.nan values with None, but that is compute intensive and takes up much more space.<br />
<br />
Is it possible to open a pull request on mysql-connector github to fix this?]]></description>
            <dc:creator>Berel Levy</dc:creator>
            <category>Connector/Python</category>
            <pubDate>Wed, 17 Aug 2022 15:06:40 +0000</pubDate>
        </item>
    </channel>
</rss>
