您好,我想请教一下如何配置 MySQL 读写分离?我根据 ThinkJS 的官方文档配置但是出错了。
BTW:文档里面的 MYSQL_WRITE 的 host 后面是不是少了个逗号?
const MYSQL_WRITE = {
host: "10.0.10.2"
}
因为开发版和我们使用的版本有点不一样,如 export default 和 exports.default,host 加了引号等。
如下配置会出现服务器 500 错误。
"use strict";
exports.__esModule = true;
const MYSQL_READ = {
"host": "192.168.1.2",
"port": "3306",
"database": "firekylin",
"user": "aaa",
"password": "bbb",
"prefix": "fk_",
"type": "mysql"
}
const MYSQL_WRITE = {
"host": "192.168.1.1",
"port": "3306",
"database": "firekylin",
"user": "aaa",
"password": "bbb",
"prefix": "fk_",
"type": "mysql"
}
exports.default = {
"type": "mysql",
"adapter": {
"mysql": {
"parser": function(options){
let sql = options.sql;
if(sql.indexOf("SELECT") === 0){
return MYSQL_READ;
}
return MYSQL_WRITE;
}
}
}
}
而如下配置会无法启动,502 错误:
"use strict";
exports.__esModule = true;
const MYSQL_READ = {
"host": "192.168.1.2",
}
const MYSQL_WRITE = {
"host": "192.168.1.1",
}
exports.default = {
"type": "mysql",
"adapter": {
"mysql": {
"parser": function(options){
let sql = options.sql;
if(sql.indexOf("SELECT") === 0){
return MYSQL_READ;
}
return MYSQL_WRITE;
}
"port": "3306",
"database": "firekylin",
"user": "aaa",
"password": "bbb",
"prefix": "fk_",
"type": "mysql"
}
}
}