python - pymysql - 谷歌云 - 操作错误 : (2003, "Can' t 连接到 MySQL 服务器

标签 python mysql google-app-engine

我的Python代码非常简单:

import pymysql as pymysql
db = pymysql.connect(
            host='*.172', user="*one", passwd=CLOUDSQL_PASSWORD,
    database='my_db_name')

我在这里创建了 MySQL 实例: enter image description here

在这里创建了一个数据库: enter image description here

并授予用户访问权限: enter image description here

但我不断收到以下错误:

---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-53-1f1166ca5290> in <module>()
      1 db = pymysql.connect(
      2             host='*.172', user=CLOUDSQL_USER, passwd=CLOUDSQL_PASSWORD,
----> 3     database='*one')

C:\ProgramData\Anaconda2\lib\site-packages\pymysql\__init__.pyc in Connect(*args, **kwargs)
     88     """
     89     from .connections import Connection
---> 90     return Connection(*args, **kwargs)
     91 
     92 from . import connections as _orig_conn

C:\ProgramData\Anaconda2\lib\site-packages\pymysql\connections.pyc in __init__(self, host, user, password, database, port, unix_socket, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, ssl, read_default_group, compress, named_pipe, no_delay, autocommit, db, passwd, local_infile, max_allowed_packet, defer_connect, auth_plugin_map, read_timeout, write_timeout, bind_address)
    704             self._sock = None
    705         else:
--> 706             self.connect()
    707 
    708     def _create_ssl_ctx(self, sslp):

C:\ProgramData\Anaconda2\lib\site-packages\pymysql\connections.pyc in connect(self, sock)
    961                 exc.traceback = traceback.format_exc()
    962                 if DEBUG: print(exc.traceback)
--> 963                 raise exc
    964 
    965             # If e is neither DatabaseError or IOError, It's a bug.

OperationalError: (2003, "Can't connect to MySQL server on '*.172' (timed out)")

如有任何帮助,我们将不胜感激。

最佳答案

您必须在授权网络下添加您的 ipv4 地址。

https://cloud.google.com/sql/docs/mysql/connect-admin-ip

关于python - pymysql - 谷歌云 - 操作错误 : (2003, "Can' t 连接到 MySQL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43335794/

相关文章:

Mysql 匹配数字关键字

php - PDO Mysql,想要更新甚至插入数据

android - 客户端与 Cloud Endpoints 的客户端通信

python - 使用 Python 解析 HTTP 请求授权 header

python - 在 Qt 5 中嵌入 Python

python - 为什么Python的pprint模块会检查sys.modules中的 `"区域设置?

mysql - 使用 sequelize.js 在 2 个表之间嵌套 mysql 事务

python - 使用 rtmplite 在 Google App Engine 中录制音频?

python - 最Pythonic的方式来处理对话框?

python - R(或Python)创建具有渐进分割的矩形 TreeMap