Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

mysql - How to set max_allowed_packet parameter from python script to run heavy sql-queries?

I am running heavy SQL-querys from python using mysql.connector package and generating pandas dataframes from the outputs. I've been capable to run small and medium size queries succesfully, but I did that because I was learning how to do this process (I am new on python and SQL). When I run a heavy query, I always get the error:

2013: Lost connection to MySQL server during query

So, I read in a web-site to the fact that since the query take several minutes to finish, this error arises and it can be fixed by setting max_allowed_packet parameter to a higher value from its default value, but I do not how to do it. My code is the following:

import mysql.connector
import pandas as pd

try:
    mydb = mysql.connector.connect(user     = 'xxxxxxxx',
                                   password = 'xxxxxxxx',
                                   host     = 'xxxxxxxx',
                                   port     = '3306',
                                   raise_on_warnings = True)
    with open('query_1.txt','r') as consulta:
        query_1 = consulta.readlines()
    
    query_1 = ' '.join(map(str, query_1)) 
    result_dataFrame = pd.read_sql(str(query_1),mydb)
    mydb.close() #close the connection
except Exception as e:
    mydb.close()
    print(str(e))

The query is in the query_1 text file. So, How do I set the max_allowed_packet parameter? What is the highest value?

question from:https://stackoverflow.com/questions/65839496/how-to-set-max-allowed-packet-parameter-from-python-script-to-run-heavy-sql-quer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...