Sequelize的读写分离操作(Eggjs为例)
-
读写分离操作基于主从复制,请在主从复制部署好之后再进行读写分离操作
config.sequelize = { dialect: 'mysql', replication: { read: [ { host: '127.0.0.1', username: 'root', port: 33306, password: '123456' }, { host: '127.0.0.1', username: 'root', port: 43306, password: '123456' }, ], write: { host: '127.0.0.1', username: 'root',port: 23306, password: '123456' } }, database: 'test', timezone: '+08:00', };
其中端口23306为主库进行写操作和事务查询,33306和43306为从库只进行select查询。