Skip to content

Commit 7879b3e

Browse files
committed
Bug #18415196 MYSQL_UPGRADE DUPLICATE KEY ERROR FOR MYSQL.USER FOR 5.5.35+, 5.6.15+, 5.7.3+
Description: mysql_upgrade fails with below error, when there are duplicate entries(like 'root'@'LOCALHOST' and 'root'@'localhost') in mysql.user table. ERROR 1062 (23000) at line 1140: Duplicate entry 'localhost-root' for key 'PRIMARY' FATAL ERROR: Upgrade failed Analysis: As part of the bug 12917151 fix we are making all the hostnames as lower case hostnames. So, this has been done by mysql_upgrade. In case of above mentioned duplicate entries mysql_upgrade tries to change hostname to lowercase. Since there is already 'root'@'localhost' exists. it is failing with "duplicate entry" error. Fix: Since its a valid error failure. We are making the error more verbose. So, that user will delete the duplicate errors manually. Along with existing error we are printing below error as well. ERROR 1644 (45000) at line 1153: Multiple accounts exist for @user_name, @host_name that differ only in Host lettercase; remove all except one of them
1 parent 3a29e14 commit 7879b3e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

scripts/mysql_system_tables_fix.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,25 @@ INSERT INTO tmp_proxies_priv VALUES ('localhost', 'root', '', '', TRUE, '', now(
652652
INSERT INTO proxies_priv SELECT * FROM tmp_proxies_priv WHERE @had_proxies_priv_table=0;
653653
DROP TABLE tmp_proxies_priv;
654654

655+
-- Checking for any duplicate hostname and username combination are exists.
656+
-- If exits we will throw error.
657+
DROP PROCEDURE IF EXISTS mysql.count_duplicate_host_names;
658+
DELIMITER //
659+
CREATE PROCEDURE mysql.count_duplicate_host_names()
660+
BEGIN
661+
SET @duplicate_hosts=0;
662+
SET @duplicate_hosts=(SELECT count(*) FROM mysql.user GROUP BY user, lower(host) HAVING count(*) > 1 LIMIT 1);
663+
select @duplicate_hosts;
664+
IF @duplicate_hosts > 1 THEN
665+
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Multiple accounts exist for @user_name, @host_name that differ only in Host lettercase; remove all except one of them';
666+
END IF;
667+
END //
668+
DELIMITER ;
669+
CALL mysql.count_duplicate_host_names();
670+
-- Get warnings (if any)
671+
SHOW WARNINGS;
672+
DROP PROCEDURE mysql.count_duplicate_host_names;
673+
655674
# Convering the host name to lower case for existing users
656675
UPDATE user SET host=LOWER( host ) WHERE LOWER( host ) <> host;
657676

0 commit comments

Comments
 (0)