Skip to content

Commit 46b617d

Browse files
committed
Bug #12917164 DROP USER CAN'T DROP USERS WITH LEGACY
UPPER CASE HOST NAME ANYMORE Description: It is not possible to drop users with host names with upper case letters in them. i.e DROP USER 'root'@'Tmp_Host_Name'; is failing with error. Analysis: Since the fix 11748570 we came up with lower case hostnames as standard. But in the current bug the hostname is created by mysql_install_db script is still having upper case hostnames. So, if we have the hostname with upper case letters like(Tmp_Host_Name) then we will have as it is stored in the mysql.user table. In this case if use "'DROP USER 'root'@'Tmp_Host_Name';" it gives error because we do compare with the lower case of hostname since the 11748570 fix. Fix: We need to convert the hostname to lower case before storing into the mysql.user table when we run the mysql_install_db script.
1 parent 3d553c2 commit 46b617d

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

scripts/mysql_system_tables_data.sql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
-- Get the hostname, if the hostname has any wildcard character like "_" or "%"
2626
-- add escape character in front of wildcard character to convert "_" or "%" to
2727
-- a plain character
28-
SET @get_hostname= @@hostname;
29-
SELECT REPLACE((SELECT REPLACE(@get_hostname,'_','\_')),'%','\%') INTO @current_hostname;
28+
SELECT LOWER( REPLACE((SELECT REPLACE(@@hostname,'_','\_')),'%','\%') )INTO @current_hostname;
3029

3130

3231
-- Fill "db" table with default grants for anyone to
@@ -42,9 +41,9 @@ DROP TABLE tmp_db;
4241
-- from local machine if "user" table didn't exist before
4342
CREATE TEMPORARY TABLE tmp_user LIKE user;
4443
INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
45-
REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0 FROM dual WHERE LOWER( @current_hostname) != 'localhost';
44+
REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0 FROM dual WHERE @current_hostname != 'localhost';
4645
REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
4746
INSERT INTO tmp_user (host,user) VALUES ('localhost','');
48-
INSERT INTO tmp_user (host,user) SELECT @current_hostname,'' FROM dual WHERE LOWER(@current_hostname ) != 'localhost';
47+
INSERT INTO tmp_user (host,user) SELECT @current_hostname,'' FROM dual WHERE @current_hostname != 'localhost';
4948
INSERT INTO user SELECT * FROM tmp_user WHERE @had_user_table=0;
5049
DROP TABLE tmp_user;

scripts/mysql_system_tables_fix.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ ALTER TABLE db MODIFY Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT
601601

602602
UPDATE user SET Trigger_priv=Super_priv WHERE @hadTriggerPriv = 0;
603603

604+
# Convering the host name to lower case for existing users
605+
UPDATE user SET host=LOWER( host ) WHERE LOWER( host ) <> host;
606+
604607
# Activate the new, possible modified privilege tables
605608
# This should not be needed, but gives us some extra testing that the above
606609
# changes was correct

0 commit comments

Comments
 (0)