4

Hello I have a mariaDB database on a Ubuntu server running in a virtual box. With 'Sequal Pro' i can connect without any problems (with the ssh option). Port forwarding like this: HOST 127.0.0.1 3306 GAST 10.0.2.15 3306

But in my python application i can't connect, or better it lost the connection before it can do something, with the following error:

OperationalError: (OperationalError) (2013, 'Lost connection to MySQL server during query') None None

I use SqlAlchemy with the mysqldb connector, like this: In the init.py file in models directory:

# for this must install pymsql (pip install pymysql)
DATABASE = 'mysql+pymysql://<user>:<password>@127.0.0.1/fist-test'

app.debug = DEBUG
app.secret_key = 'secret-key123'
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE
db = SQLAlchemy(app)

In the project main directory in the main.py file:

from models import db

@app.route('/test')
def test():
    db.create_all()
    return 'create objects...'

if __name__ == '__main__':
    app.run()

In models is also some model class:

from sqlalchemy import Column, Integer, String

class User(Base):
     __tablename__ = 'users'

     id = Column(Integer, primary_key=True)
     name = Column(String)
     fullname = Column(String)
     password = Column(String)

     def __init__(self, name, fullname, password):
         self.name = name
         self.fullname = fullname
         self.password = password

     def __repr__(self):
        return "<User('%s','%s', '%s')>" % (self.name, self.fullname, self.password)

Hope someone can help me to understand and solve the problem.

Thanks for your time!

1 Answer 1

1

This is probably because MariaDB has a much shorter default timeout of 600 seconds. See the timeout documentation here: flask-sqlalchemy timeout docs

I would recommend setting the SQLALCHEMY_POOL_RECYCLE to less than 600 seconds so that the server does not time out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.