楼主: jabincn

MYSQl Proxy 多连接的错误can't change DB to on slave

[复制链接]
论坛徽章:
0
11#
 楼主| 发表于 2008-5-23 20:04 | 只看该作者
继续查找解决方法......

使用道具 举报

回复
论坛徽章:
0
12#
 楼主| 发表于 2008-5-24 09:11 | 只看该作者
找到这个文章里写的内容:

http://jan.kneschke.de/projects/ ... -more-r-w-splitting

Improvements
keeping default-db in sync

One of the basic problems with rw-splitting is that each connection has a state, e.g. the default_db. If you switch to another backend you have to make sure that before we issue a SQL query, that also set the new default-db, if they are not in sync.

[read_query]
  current backend   = 0
  client default db = mysql
  client username   = root
  query             = select * from user
    server default db: repl
    client default db: mysql
    syncronizing

The client-side did a USE mysql against the master and wanted to SELECT from the a slave afterwards. As the connection the slave was still using repl from the previous query we have apply the DB-change now. For achieve this we insert a USE mysql before sending the SELECT to the slave.

In case the DB want to switch to doesn't exist on the slave, you will get an error like:

ERROR 1000 (00S00): can't change DB 'norepl' to on slave ':3307'

for the SELECT statement.
Stateful SQL Statements

Not all statements in MySQL are stateless and allow easy R/W splitting. Some of them need special support to make sure that still work:

    * SELECT SQL_CALC_FOUND_ROWS ... will lead to a SELECT FOUND_ROWS() which has to be executed on the same connection
    * INSERTing into table with auto_increment fields might lead to a SELECT LAST_INSERT_ID() which has to be execute on the same master-connection.
    * SHOW WARNINGS is similar

The solution is simple: don't give away the connection in that cases and don't send the SELECT FOUND_ROWS() to a slave. For sure there are some more statements which might not harmonize with r/w splitting. For example prepared statements. But that's another story.

使用道具 举报

回复
论坛徽章:
52
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:25生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:32:552012新春纪念徽章
日期:2012-02-07 09:59:35
13#
发表于 2008-5-24 13:26 | 只看该作者
这么说就是MySQL-Proxy缺乏根据SQL语句或者是连接默认的DBName改变当前默认的数据库,
要是做到这点。。就不存在BUG了

使用道具 举报

回复
论坛徽章:
0
14#
 楼主| 发表于 2008-5-24 13:33 | 只看该作者
原帖由 jinguanding 于 2008-5-24 13:26 发表
这么说就是MySQL-Proxy缺乏根据SQL语句或者是连接默认的DBName改变当前默认的数据库,
要是做到这点。。就不存在BUG了


哥们来了,我还没有找到解决问题的方法。

嗯,MySQL-Proxy缺乏根据SQL语句或者是连接默认的DBName改变当前默认的数据库。

使用道具 举报

回复
论坛徽章:
0
15#
 楼主| 发表于 2008-5-24 13:38 | 只看该作者
proxy输出日志中:
  server default db: cjhjd
    client default db:
    syncronizing
    server default db: cjhjd
    client default db:
    syncronizing
    server default db: cjhjd
    client default db:
    syncronizing
    server default db:
    client default db: cjhjd
    syncronizing


发现当client default db: 没有值 的时候就会出现这个问题。

使用道具 举报

回复
论坛徽章:
40
生肖徽章2007版:马
日期:2008-04-07 19:43:48管理团队成员
日期:2011-05-07 01:45:082012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:09马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14
16#
发表于 2008-5-24 13:40 | 只看该作者
You have to explicitly point the exact database.
I have already introduced in my article.

使用道具 举报

回复
论坛徽章:
40
生肖徽章2007版:马
日期:2008-04-07 19:43:48管理团队成员
日期:2011-05-07 01:45:082012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:092012新春纪念徽章
日期:2012-02-13 15:08:09马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14
17#
发表于 2008-5-24 13:41 | 只看该作者
Since you got the correct answer.
Congratulations.

使用道具 举报

回复
论坛徽章:
0
18#
 楼主| 发表于 2008-5-24 13:45 | 只看该作者
杨兄,知道问题所在,可是还没找到解决方法。

杨兄的文章中我还没有找到解决方法,请指教。

使用道具 举报

回复
论坛徽章:
1
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44
19#
发表于 2008-5-24 13:56 | 只看该作者
学习。

使用道具 举报

回复
论坛徽章:
0
20#
 楼主| 发表于 2008-5-24 14:00 | 只看该作者
原帖由 爱佟儿 于 2008-5-24 13:56 发表
学习。


哥们是李同志?

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表