gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:53:39 24 4
gpt4 key购买 nike

我的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com