我错误地输入了这个mysql命令:
INSERT INTO `alias` (`source`, `destination`) VALUES ("@localhost.localdomain", "@localhost"), ("@localhost", "email1@domain1.com");
我想从mysql数据库中删除或更新电子邮件地址email1@domain1.com
,因为当我尝试插入时:
INSERT INTO `alias` (`source`, `destination`) VALUES ("@localhost.localdomain", "@localhost"), ("@localhost", "goodaccount@domain.com");
我收到了错误:
ERROR 1062 (23000): Duplicate entry '@localhost.localdomain' for key 'PRIMARY'
答案 0 :(得分:0)
字段source
是alias
表中的主键。并且您不能一次又一次地在PK字段中插入相同的值。当您在PK字段中再次插入相同的值时,您收到此错误
您可以像这样更新电子邮件
UPDATE alias SET destination = 'goodaccount@domain.com' WHERE source = "@localhost";
删除
DELETE FROM alias WHERE destination = 'email1@domain1.com' AND source = "@localhost";
答案 1 :(得分:0)
插入时出错。你插入两个!!行,但你只需要一个。
INSERT INTO `alias` (`source`, `destination`) VALUES ("@localhost", "goodaccount@domain.com");
DELETE FROM `alias` WHERE `destination` = 'email1@domain1.com' and `source` = '@localhost.localdomain';