How to properly grant access to a database user in Google Cloud SQL?
<p>I've been stuck with this problem for a couple of days.</p>

<p>I developed an application for appengine using Django and I'd like to use Google Cloud SQL for my database. Everything works fine until I want to apply migrations on the development server when it fails with the following error:</p>

<pre><code>django.db.utils.OperationalError: (1045, "Access denied for user 'MY_DB_USER'@'MY_IP' (using password: YES)")
</code></pre>

<p>What I've done is as follows:</p>

<ol>
<li><p>I followed the instructions in the <a href="https://cloud.google.com/appengine/docs/python/cloud-sql/django" rel="nofollow">Django Support</a> page to
develop my application.   </p></li>
<li><p>In order to create a 1st generation Cloud SQL instance I followed
the steps outlined <a href="https://cloud.google.com/sql/docs/getting-started" rel="nofollow">here</a>, using the Cloud SDK.</p></li>
<li>I then created a new user following the instructions <a href="https://cloud.google.com/sql/docs/create-user" rel="nofollow">here</a> and assigned it a password.</li>
<li><p>I deployed the application using the following command line:</p>

<p>gcloud preview app deploy MY-APP-DIR/app.yaml --version 0-1-0</p></li>
<li><p>I authorized my IP and my AppEngine Application ID. They are both listed in the ''Authorization'' section under ''Access Control'' in my SQL instance. </p></li>
<li><p>Finally, I tried to apply migrations using the following command line:</p>

<p>SETTINGS_MODE='prod' MY-APP-DIR/manage.py migrate</p></li>
</ol>

<p><strong>settings.py</strong></p>

<p>The relevant portion of my settings.py looks as follows:</p>

<pre><code>if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
    DEBUG = False
    # Running on production App Engine, so use a Google Cloud SQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST' : '/cloudsql/[MY-PROYECT-ID]:[MY-CLOUD-SQL-INSTANCE]',
            'NAME': '[MY-DB-NAME]',
            'USER': 'root',
        }
    }
elif os.getenv('SETTINGS_MODE') == 'prod':
    DEBUG = False
    # Running in development, but want to access the Google Cloud SQL instance
    # in production.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': '[MY-DB-NAME]', # db name. 
            'USER': '[MY-DB-USER]',
            'PASSWORD' : '[MY-DB-USER-PASSWORD]',
            'HOST' : '[IPV4 ASSIGNED IN GOOGLE CONSOLE]',
            'PORT': '3306',
        }
    }
else:
    # Running in development, so use a local MySQL database.
    DEBUG = True
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': '[MY-LOCAL-DB]',
            'USER': 'root',
            'PASSWORD': 'root',
        }
    }
</code></pre>

<p>Any idea as to what might be causing the problem?</p>

<p>Thank you!</p>