我正在尝试将MySQL连接到python,我已经成功安装了Mysql连接器,但是当我尝试链接到数据库时失败了。
$ import mysql.connector
connection = mysql.connector.connect(host="xx.xx.xx.xx",user ="xxx",passwd ="xxx",database="xxx",port=xxx)
我得到的错误
<ipython-input-31-a02432f5c7d5> in <module>
connection = mysql.connector.connect(host="172.16.16.114",user ="EDWH",passwd ="EDWH12",database="HOBANK",port =1521) return CMySQLConnection(*args, **kwargs) else - return MySQLConnection(*args, **kwargs) Connect = connect # pylint: disable=C0103
------------------------------------------------------------------------
c:\users\achille.ntwari\appdata\local\programs\python\python37\lib\site-packages\mysql\connector\connection.py in __init__(self, *args, **kwargs) if len(kwargs) > 0: self.connect(**kwargs) def _do_handshake(self)
------------------------------------------------------------------------
c:\users\achille.ntwari\appdata\local\programs\python\python37\lib\site-packages\mysql\connector\abstracts.py in connect(self, **kwargs) self.disconnect() ,self._open_connection() self._post_connection()
c:\users\achille.ntwari\appdata\local\programs\python\python37\lib\site-packages\mysql\connector\connection.py in _open_connection(self) self._socket = self._get_connection() self._socket.open_connection() self._do_handshake() self._do_auth(self._user, self._password, self._database, self._client_flags, self._charset_id,
------------------------------------------------------------------------
c:\users\achille.ntwari\appdata\local\programs\python\python37\lib\site-packages\mysql\connector\connection.py in _do_handshake(self) def _do_handshake(self): """Get the handshake from the MySQL server""" packet = self._socket.recv() if packet[4] == 255: raise errors.get_exception(packet)
------------------------------------------------------------------------
c:\users\achille.ntwari\appdata\local\programs\python\python37\lib\site-packages\mysql\connector\network.py in recv_plain(self) chunk = self.sock.recv(4 - packet_len) if not chunk: raise errors.InterfaceError(errno=2013) packet += chunk packet_len = len(packet)
------------------------------------------------------------------------
InterfaceError: 2013: Lost connection to MySQL server during query`enter code here`