无法在Google CloudSQL上运行syncdb OperationalError 1045拒绝访问用户&root;' @' localhost'使用密码:没有

时间:2014-08-19 10:23:38

标签: python mysql django google-app-engine python-2.7

根据以下google documentationtutorials,我进行了以下设置。

我从未让谷歌提示我提供oauth令牌网址。因为它应该根据他们的文件。我不确定出了什么问题。
可能有人可以在syncdb上使用--traceback尝试-v 3选项,并告诉我在使用syncdb时调用的路径和库。 https://accounts.google.com/o/oauth2/auth.

这是我尝试使用syncdb连接的错误

$ SETTINGS_MODE='prod' python manage.py  syncdb -v 3 --traceback  
Traceback (most recent call last):  
  File "/home/user/bin/lib/google_appengine/lib/django-1.5/django/core/management/base.py", line 222, in run_from_argv  
    self.execute(*args, **options.__dict__)  
  File "/home/user/bin/lib/google_appengine/lib/django-1.5/django/core/management/base.py", line 255, in execute  
    output = self.handle(*args, **options)  
  File "/home/user/bin/lib/google_appengine/lib/django-1.5/django/core/management/base.py", line 385, in handle  
    return self.handle_noargs(**options)  
  File "/home/user/bin/lib/google_appengine/lib/django-1.5/django/core/management/commands/syncdb.py", line 56, in handle_noargs  
    cursor = connection.cursor()  
  File "/home/user/bin/lib/google_appengine/lib/django-1.5/django/db/backends/__init__.py", line 324, in cursor  
    cursor = self.make_debug_cursor(self._cursor())  
  File "/home/user/bin/lib/google_appengine/lib/django-1.5/django/db/backends/mysql/base.py", line 406, in _cursor  
    self.connection = Database.connect(**kwargs)  
  File "/home/user/projects/my-app/src/my-app/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect  
    return Connection(*args, **kwargs)  
  File "/home/user/projects/my-app/src/my-app/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__  
    super(Connection, self).__init__(*args, **kwargs2)  
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")  

当我尝试使用特定版本的django时,它带有GAE并使用manage.py提供的设置设置PATH。我得到完全相同的错误。

SETTINGS_MODE='prod' python ../lib/google_appengine/lib/django-1.5/django/bin/django- admin.py  syncdb -v 3 --traceback --settings=opexdash.settings --pythonpath=. 

然而,我可以使用dbshel​​l解决任何问题。

$ SETTINGS_MODE='prod' python manage.py dbshell  
Reading table information for completion of table and column names  
You can turn off this feature to get a quicker startup with -A  

Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 54  
Server version: 5.5.39 (Google)  

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  

Oracle is a registered trademark of Oracle Corporation and/or its  
affiliates. Other names may be trademarks of their respective  
owners.  

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  

mysql> select @@hostname;  
+------------+  
| @@hostname |  
+------------+  
| localhost  |  
+------------+  
1 row in set (0.40 sec)  

mysql> select database();  
+------------+  
| database() |  
+------------+  
| my_db      |  
+------------+  
1 row in set (0.32 sec)  

以下是我根据文档使用的其他设置。

if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):  
    # Running on production App Engine, so use a Google Cloud SQL database.  
    DATABASES = {  
        'default': {  
            'ENGINE': 'django.db.backends.mysql',  
            'HOST': '/cloudsql/nth-hybrid-672:beta-dash02',  
            'NAME': 'my-app',  
            'USER': 'root',  
        }  
    }  
elif os.getenv('SETTINGS_MODE') == 'prod':  
    # Running in development, but want to access the Google Cloud SQL instance  
    # in production.  
    DATABASES = {  
        'default': {  
            #'ENGINE': 'google.appengine.ext.django.backends.rdbms',  
            'ENGINE': 'django.db.backends.mysql',  
            'INSTANCE': 'your-project-id:your-instance-name',  
            'NAME': 'my-app',  
            'USER': 'root',  
            #'HOST': '173.100.100.100',  I can synkdb using it this way with a password set, ip address has been changed for this public forum
            #'PASSWORD' : ''  
        }  
    }  
else:  
    # Running in development, so use a local MySQL database.  
    DATABASES = {  
        'default': {  
            'ENGINE': 'django.db.backends.mysql',  
            'NAME': 'gae',  
            'USER': 'gae',  
            'PASSWORD': 'gae',  
        }  
    }   

我认为这个问题很可能取决于环境设置的问题。 但是我希望当我在GAE / lib目录中使用完整路径进行管理时 它应该工作。

$PATH
/home/user/projects/my-app/src/my-app/bin:   
/usr/local/sbin:  
/usr/local/bin:  
/usr/sbin:  
/usr/bin:   
/sbin:  
/bin:  
/usr/games:  
/usr/local/games:  
/usr/lib/jvm/default-java:  
/usr/share/javadb/bin:  
/home/user/bin:  
/home/user/bin/lib/google_appengine/:  

1 个答案:

答案 0 :(得分:2)

您不需要oauth,您正在连接数据库,就像它是一个普通的远程MySQL实例一样;因此你需要

'ENGINE': 'django.db.backends.mysql',  
'NAME': 'my-app',  # your DB name
'USER': 'root',  
'HOST': '173.xxx.xxx.xxx',  # your instance's IP address
'PASSWORD' : 'your-root-password-here',

(假设您已允许自己的IP连接到实例。)您还可以设置连接以通过SSL。

Google的文档已过时,但this post comes from a Google Cloud SQL engineer并断言推荐的连接方式是将MySQL实例视为普通的远程服务器。