[英]Copy a column from one table to another in mysql (two different databases)
I tried to copy a column from one table to another table (in two different databases) 我试图将一列从一个表复制到另一个表(在两个不同的数据库中)
I tried the following queries: 我尝试了以下查询:
update des_db.mytable as des
set col= (select col from src_db.mytable as src where src.id = db.id)
and also joining these two tables. 并连接这两个表。
In both solutions, I got the error "Total number of locks exceed the lock table size". 在这两种解决方案中,我都收到错误“锁总数超过了锁表大小”。
I increased the "innodb_log_buffer_size to 32M and it doesn't work. 我将“ innodb_log_buffer_size增加到32M,它不起作用。
I want to know if there is any solution to do this. 我想知道是否有解决方案。
IMPORTANT NOTE: the source table is actually my backup and it has the same number of rows as the other one has. 重要说明:源表实际上是我的备份,它的行数与另一个表相同。 (666,666 records) (666,666条记录)
This way it should work: 这样,它应该可以工作:
UPDATE
des_db.mytable
INNER JOIN src_db.mytable ON des_db.mytable.id = src_db.mytable.id
SET
des_db.mytable.col = src_db.mytable.col;
Unfortunately I can't test it right now, but I'm quite sure this works. 不幸的是,我现在无法对其进行测试,但是我很确定这是可行的。 Aliases should work also. 别名也应该起作用。
UPDATE database1.table1, database2.table1
SET database1.table1.columnA = database2.table1.columnA
WHERE database1.table1.id = database2.table1.id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.