简体   繁体   中英

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.

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)

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM