请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

cannot connect to mysql server

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/connections.py", line 920, in connect

    **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 722, in create_connection

    raise err

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 713, in create_connection

    sock.connect(sa)

ConnectionRefusedError: [Errno 61] Connection refused


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2158, in _wrap_pool_connect

    return fn()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 403, in connect

    return _ConnectionFairy._checkout(self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 782, in _checkout

    fairy = _ConnectionRecord.checkout(pool)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 532, in checkout

    rec = pool._do_get()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1186, in _do_get

    self._dec_overflow()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__

    compat.reraise(exc_type, exc_value, exc_tb)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 187, in reraise

    raise value

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1183, in _do_get

    return self._create_connection()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 350, in _create_connection

    return _ConnectionRecord(self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 477, in __init__

    self.__connect(first_connect_check=True)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 667, in __connect

    connection = pool._invoke_creator(self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 105, in connect

    return dialect.connect(*cargs, **cparams)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 410, in connect

    return self.dbapi.connect(*cargs, **cparams)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect

    return Connection(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/connections.py", line 699, in __init__

    self.connect()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/connections.py", line 967, in connect

    raise exc

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 61] Connection refused)")


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "models.py", line 174, in <module>

    db.create_all()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 963, in create_all

    self._execute_for_all_tables(app, bind, 'create_all')

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 955, in _execute_for_all_tables

    op(bind=self.get_engine(app, bind), **extra)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/sql/schema.py", line 4004, in create_all

    tables=tables)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1939, in _run_visitor

    with self._optional_conn_ctx_manager(connection) as conn:

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 82, in __enter__

    return next(self.gen)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1932, in _optional_conn_ctx_manager

    with self.contextual_connect() as conn:

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2123, in contextual_connect

    self._wrap_pool_connect(self.pool.connect, None),

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2162, in _wrap_pool_connect

    e, dialect, self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1476, in _handle_dbapi_exception_noconnection

    exc_info

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause

    reraise(type(exception), exception, tb=exc_tb, cause=cause)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise

    raise value.with_traceback(tb)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2158, in _wrap_pool_connect

    return fn()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 403, in connect

    return _ConnectionFairy._checkout(self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 782, in _checkout

    fairy = _ConnectionRecord.checkout(pool)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 532, in checkout

    rec = pool._do_get()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1186, in _do_get

    self._dec_overflow()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__

    compat.reraise(exc_type, exc_value, exc_tb)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 187, in reraise

    raise value

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1183, in _do_get

    return self._create_connection()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 350, in _create_connection

    return _ConnectionRecord(self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 477, in __init__

    self.__connect(first_connect_check=True)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/pool.py", line 667, in __connect

    connection = pool._invoke_creator(self)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 105, in connect

    return dialect.connect(*cargs, **cparams)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 410, in connect

    return self.dbapi.connect(*cargs, **cparams)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect

    return Connection(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/connections.py", line 699, in __init__

    self.connect()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymysql/connections.py", line 967, in connect

    raise exc

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 61] Connection refused)") (Background on this error at: http://sqlalche.me/e/e3q8)


正在回答 回答被采纳积分+3

2回答

提问者 于方贤 2018-05-17 11:39:53

将mysql加入环境变量后就没这个问题了

0 回复 有任何疑惑可以回复我~
朱小飞_thebest 2018-03-16 21:51:04

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 61] Connection refused)") (Background on this error at: http://sqlalche.me/e/e3q8)

不能连接本地的mysql server,数据库服务起了吗? 数据库服务可用吗?

0 回复 有任何疑惑可以回复我~
  • 提问者 于方贤 #1
    起了的,也能进入数据库进行操作。。。
    回复 有任何疑惑可以回复我~ 2018-03-16 22:19:35
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信