gpt4 book ai didi

MySql 多个数据库。如何插入?

转载 作者:行者123 更新时间:2023-11-29 12:59:55 26 4
gpt4 key购买 nike

我有 2 个数据库,我想更新数据库 feDB 的表 fe_accounts 中的字段(插入?)uuid,以便将 NULL 替换为从数据库 NameHistoryDB 中的 NameHistory 表中购买 uuid。

数据库1

Database : NameHistoryDB
Table: NameHistory

+--------------------------------------+------------------+---------------------+---------------------+
| uuid | playername | dateadded | lastseen |
+--------------------------------------+------------------+---------------------+---------------------+
| 0b9bb8dc-051c-4d8d-9029-96d969baece1 | xRazmuz | 2014-04-09 08:40:47 | 2014-04-15 12:32:40 |
| a61925ba-8a69-464b-89c9-37d3d3fe9ce4 | Sleepyangel99 | 2014-04-09 08:45:09 | 2014-05-05 11:50:38 |
| 3983c0ef-3def-4f1b-ac15-335d6a4e1458 | pulle3 | 2014-04-09 08:51:37 | 2014-04-26 16:48:34 |
| 502f873d-7bf6-4187-bcf1-a5d78f574293 | zohan10 | 2014-04-09 09:04:37 | 2014-04-22 17:07:24 |

数据库2

Database : feDB
Table: fe_accounts

+------------------+---------+--------------------------------------+
| name | money | uuid |
+------------------+---------+--------------------------------------+
| xRazmuz | 74 | NULL |
| Sleepyangel99 | 2650 | NULL |
| pulle3 | 1000 | NULL |
| zohan10 | 1079 | NULL |

我想将数据库2中的uuid插入到数据库1中,所以结果将是这样的:

Database : feDB
Table: fe_accounts

+------------------+---------+--------------------------------------+
| name | money | uuid |
+------------------+---------+--------------------------------------+
| xRazmuz | 74 | 0b9bb8dc-051c-4d8d-9029-96d969baece1 |
| Sleepyangel99 | 2650 | a61925ba-8a69-464b-89c9-37d3d3fe9ce4 |
| pulle3 | 1000 | 3983c0ef-3def-4f1b-ac15-335d6a4e1458 |
| zohan10 | 1079 | 502f873d-7bf6-4187-bcf1-a5d78f574293 |

我该怎么做?

最佳答案

一种方法是连接两个数据库中的表,然后更新为

update feDB.fe_accounts db2
inner join NameHistoryDB.NameHistory db1 on db1.playername = db2.name
set
db2.uuid = db1.uuid
where
db2.uuid is null

NOTE : To run the above query you need proper permission i.e. mysql user having access to both DB.

Also it will match with the payername, there is no other common key to match so accurate update lies in having unique player names

关于MySql 多个数据库。如何插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23494686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com