我有2个数据库我想在数据库feDB的表fe_accounts中更新字段(insert?)uuid,以便我在数据库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 |
我该怎么做?
答案 0 :(得分:1)
一种方法是从两个数据库中加入表,然后更新为
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
注意:要运行上述查询,您需要适当的权限,即mysql 用户可以访问这两个数据库。
它也会与付款人名称相匹配,没有其他常用密钥 匹配如此准确的更新在于拥有独特的玩家名称
答案 1 :(得分:0)
按顺序运行这两个查询:
USE feDB;
UPDATE
fe_accounts
JOIN NameHistoryDB.NameHistory t2 ON playername=name
SET uuid=NameHistoryDB.NameHistory.uuid
WHERE uuid IS NULL;