2017-04-11 161 views
0

我的Python代碼非常簡單:pymysql - 谷歌雲 - OperationalError:(2003,「無法連接到MySQL服務器上

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

而且gaveaccess這裏的用戶: 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)") 

任何幫助,將不勝感激。

回答

相關問題