日期:2014-05-16  浏览次数:20703 次

问一个两个表联合更新的问题
数据库 `bbs` 是当前正在用的数据库,一周前转移服务器导入的时候有些文字乱码,但因为有很多新数据,不能恢复到1周前.

数据库 `bbs2` 是1周前的数据库.

现在想把 bbs 中的表 cdb_posts 以前的数据更新至旧版(主键为 pid),应该怎么写?

update `bbs`.cdb_posts as x, `bbs2`.cdb_posts as y
set x.subject=y.subject, x.message=y.message
where x.pid=y.pid and y.pid>0; 

这样写有问题吗?

------解决方案--------------------
恢复到以前的数据是否开启的二进制日志文件。
可以利用日志文件恢复
------解决方案--------------------
没什么问题 最好你按照这个表的id一段一段更新 这样不至于新库压力太大或者锁表


update `bbs`.cdb_posts as x, `bbs2`.cdb_posts as y
set x.subject=y.subject, x.message=y.message
where x.pid=y.pid and y.pid>0 and x.id between 1 and 1000;