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!