【问题标题】:Can't run syncdb on Google CloudSQL OperationalError 1045 Access denied for user 'root'@'localhost' using password: NOCan't run syncdb on Google CloudSQL OperationalError 1045 Access denied for user 'root'@'localhost' using password: NO
【发布时间】:2014-10-12 09:53:50
【问题描述】:

基于以下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/:  

【问题讨论】:

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


    【解决方案1】:

    您不需要 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 实例视为普通的远程服务器。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2018-08-17
    • 2012-04-28
    • 1970-01-01
    相关资源
    最近更新 更多