title: Error connecting to MySql database with SQLalchemy
body: <p>I am giving it a last try before I give up, I have googling everywhere but still havent found a solution to my error.</p>
  <p>Just so clarify some things:</p>
  <ul>
  <li>MySql server IS UP and running</li>
  <li>I am running and PHP admin panel together with mysql in the same server(confirming once again that the mysql server works)</li>
  <li>The connection to the server is TCP</li>
  <li>When i run this python script locally on my windows machine with XAMPP, it works as it should.</li>
  </ul>
  <p>When i create docker image and run it, i get the following error:</p>
  <pre><code>sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (2002, &quot;Can't con                    nect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)&quot;)
  </code></pre>
  <p>So here is my &quot;main.py&quot; file:</p>
  <pre><code>    from flask import Flask, request
  from flask_sqlalchemy import SQLAlchemy
  from flask_marshmallow import Marshmallow
  from flask_restful import Api, Resource
  from flask_mysqldb import MySQL
  
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://myUser:myPassword@MyIpAdress/just_a_test'
  
  
  
  db = SQLAlchemy(app)
  ma = Marshmallow(app)
  api = Api(app)
  
  
  
  
  #------------------------------------------------------------------------------------------------------
  class exercise(db.Model):
      exerciseId = db.Column(db.Integer(), primary_key=True)
      exerciseName = db.Column(db.String(50))
      repetitions = db.Column(db.Integer())
      timeTakenToCompleteRepetitions = db.Column(db.Integer())
  
  
  
  class exerciseSchema(ma.SQLAlchemyAutoSchema):
      class Meta:
          model = exercise
  
  
  exercise_schema = exerciseSchema()
  exercises_schema = exerciseSchema(many=True)
  
  
  class exerciseListResource(Resource):
  
      def get(self):
          exercise = exercise.query.all()
          return exercises_schema.dump(exercise)
  
      def post(self):
          new_exercise = exercise(
              exerciseId=request.json['exerciseId'],
              exerciseName=request.json['exerciseName'],
              repetitions=request.json['repetitions'],
              timeTakenToCompleteRepetitions=request.json['timeTakenToCompleteRepetitions']
          )
          db.session.add(new_exercise)
          db.session.commit()
          return_data = exercise_schema.dump(new_exercise)
          return return_data, 201
  
  
  
  class exerciseResource(Resource):
      def get(self, exercise_exerciseId):
          exercise = exercise.query.get_or_404(exercise_exerciseId)
          return exercise_schema.dump(exercise)
  
      def patch(self, exercise_exerciseId):
          exercise = exercise.query.get_or_404(exercise_exerciseId)
  
          if request.json.get('exerciseName'):
              exercise.exerciseName = request.json['exerciseName']
          if request.json.get('repetitions'):
              exercise.repetitions = request.json['repetitions']
          if request.json.get('timeTakenToCompleteRepetitions'):
              exercise.timeTakenToCompleteRepetitions = request.json['timeTakenToCompleteRepetitions']
  
          db.session.commit()
          return exercise_schema.dump(exercise)
  
      def delete(self, exercise_exerciseId):
          exercise = exercise.query.get_or_404(exercise_exerciseId)
          db.session.delete(exercise)
          db.session.commit()
          return '', 204
  
  
  api.add_resource(exerciseListResource, '/exercise')
  api.add_resource(exerciseResource, '/exercise/&lt;int:exercise_exerciseId&gt;')
  #---------------------------------------------------------------------------------------------------
  
  
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  <p>What could the problem be?</p>