Eric Lee
Eric Lee

Reputation: 710

Is there a way to connect mysql while a python application running?

I'd like to make an python application and retrieve query results from mysql server.

So every time when an event happened, the application connect to mysql through mysqlclient like below

# retrieve query result from db
db=_mysql.connect(host="localhost",user="root",
                  passwd="password",db="db")

Is there a way not to try to connect every time but keep the connection?

Upvotes: 0

Views: 56

Answers (1)

ElapsedSoul
ElapsedSoul

Reputation: 825

Change

begin loop:
    get MQ msg
    db=_mysql.connect(host="localhost",user="root",
                  passwd="password",db="db")
    db.insert()

to

db=_mysql.connect(host="localhost",user="root",
                  passwd="password",db="db")
begin loop:
    get MQ msg
    db.insert()

Upvotes: 1

Related Questions