这是我的代码:
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'
如何启用故障转移数据库?
答案 0 :(得分:1)
failover
值应该是包含故障转移服务器的连接详细信息的列表或字典元组。例如:
failoverConfig = {
'user': 'failover_user',\
'password': 'failover_password',\
'host': 'failover_host',\
}
config = {
'user': 'testeng',\
'password': 'testeng',\
'host': 'adb',\
'failover': [failover_config],\
}