failover选项在mysql.connector中引发错误

lzfw57am  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(327)

这是我的密码:

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'

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

a14dhokn

a14dhokn1#

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

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

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

相关问题