twn39 / code

:memo: 代码笔记,通过 issue 的方式记录日常遇到的问题和学习笔记
13 stars 1 forks source link

mysql-router #66

Open twn39 opened 9 years ago

twn39 commented 9 years ago

mysql-router 路由配置

twn39 commented 9 years ago

配置文件:/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()