故障转移选项在mysql.connector中引发错误

时间:2018-11-16 11:38:21

标签: python mysql python-2.7 mysql-connector-python

这是我的代码:

import mysql.connector

config = {
        'user': 'bb123',\
        'password': 'tt',\
        'host': 'adb',\
        'failover': 'bdb',\
        }

 self.conn = mysql.connector.connect(**self.config)

但是,我遇到此错误:

return _get_failover_connection(**kwargs)
  File "C:\Python27\lib\site-packages\mysql\connector\__init__.py", line 109, in _get_failover_connection
    diff = set(server.keys()) - support_cnx_args
AttributeError: 'str' object has no attribute 'keys'

如何启用故障转移数据库?

1 个答案:

答案 0 :(得分:1)

failover值应该是包含故障转移服务器的连接详细信息的列表或字典元组。例如:

failoverConfig = {
                'user': 'failover_user',\
                'password': 'failover_password',\
                'host': 'failover_host',\
                }

config = {
        'user': 'testeng',\
        'password': 'testeng',\
        'host': 'adb',\
        'failover': [failover_config],\
        }