我有一个CSV文件,包含50,000行数据和2列。
这些列是用户ID和twitter配置文件照片。
24525,https://pbs.twimg.com/profile_images/666407537084796928/YBGgi9BO.png
27753,https://pbs.twimg.com/profile_images/2284174752/64pe9ctjko2omrtcij7a.png
24434,https://pbs.twimg.com/profile_images/638751551457103872/KN-NzuRl.png
19911,https://pbs.twimg.com/profile_images/1240079072/logo-mysql-170x170.png
我有一个MYSQL数据库,我有兴趣更新如下所示的一个表。
umeta_id - primary key ( we do not have this in our csv )
user_id - This is the first column in our csv
meta_key - We want to update when meta_key is 'twitter_photo'
meta_value - twitter profile photos go here
我可以用这样的查询更新1行
UPDATE `wp_usermeta`
SET meta_value='https://pbs.twimg.com/profile_images/666407537084796928/YBGgi9BO.png'
WHERE meta_key LIKE 'twitter_photo'
AND user_id='24525';
我一直在努力弄清楚如何做多行。我试过了,但没有用。
UPDATE `wp_usermeta` SET `meta_value` = CASE `user_id`
WHEN 24525 THEN 'https://pbs.twimg.com/profile_images/666407537084796928/YBGgi9BO.png'
WHEN 27753 THEN 'https://pbs.twimg.com/profile_images/2284174752/64pe9ctjko2omrtcij7a.png'
WHEN 24434 THEN 'https://pbs.twimg.com/profile_images/638751551457103872/KN-NzuRl.png'
ELSE `meta_value`
END,
WHERE `user_id` IN (24525, 27753, 24434) AND `meta_key` LIKE 'twitter_photo';
如能在正确的方向提供任何帮助,我们将不胜感激。
发布于 2015-12-03 06:44:35
使用csv中的两个字段和
load data infile '/path/your.csv' into table temp FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’;
然后执行连接
update wp_usermeta, temp set wp_usermeta.meta_value=temp.meta_value where wp_usermeta.user_id=temp.user_id;
https://dba.stackexchange.com/questions/122747
复制相似问题