mysql-router 路由配置

配置文件: /etc/mysqlrouter/mysqlrouter.ini

[DEFAULT]
logging_folder = /var/log/mysqlrouter/
plugin_folder = /usr/lib/x86_64-linux-gnu/mysqlrouter
runtime_folder = /var/run/mysqlrouter
config_folder = /etc/mysqlrouter

[logger]
level = info

# If no plugin is configured which starts a service, keepalive
# will make sure MySQL Router will not immediately exit. It is
# safe to remove once Router is configured.
[keepalive]
interval = 60

[routing:slave]
bind_port = 7001
mode = read-only
destinations = slave.example.com,slave2.example.com
max_connections = 1500

bind_port 为链接本地的路由端口, destinations 为链接后端的 mysql 地址。

测试:

import mysql.connector

cnx = mysql.connector.connect(host='localhost',port=7001,user='user',password='password')
cur = cnx.cursor()
cur.execute("SHOW DATABASES")
print cur.fetchall()

你可能感兴趣的