Bug #34461 rpm installation fails when hostname is 'localhost'
Submitted: 11 Feb 2008 15:31 Modified: 20 Feb 2009 18:51
Reporter: Johan Idrén Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.0.51, 5.0.54 OS:Linux (CentOS 5)
Assigned to: CPU Architecture:Any

[11 Feb 2008 15:31] Johan Idrén
Description:
When installing mysql rpm's on a system with the hostname set to 'localhost' the initialization of the system tables fail with a duplicate key error.

This was caused by the fix for bug#27692 / changeset 1.2521.34.1

--- 1.3/scripts/mysql_system_tables_data.sql	2007-04-26 07:31:19 -07:00
+++ 1.4/scripts/mysql_system_tables_data.sql	2007-09-24 06:36:05 -07:00
@@ -17,5 +17,7 @@ CREATE TEMPORARY TABLE tmp_user LIKE use
 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','','','','',0,0,0,0);
 REPLACE INTO tmp_user VALUES (@@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','','','','',0,0,0,0);
 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','','','','',0,0,0,0);
+INSERT INTO tmp_user (host,user) VALUES ('localhost','');
+INSERT INTO tmp_user (host,user) VALUES (@@hostname,'');
 INSERT INTO user SELECT * FROM tmp_user WHERE @had_user_table=0;
 DROP TABLE tmp_user;

How to repeat:
[root@localhost ~]# hostname localhost
[root@localhost ~]# hostname
localhost
[root@localhost ~]# rpm -i MySQL-server-enterprise-gpl-5.0.54a-0.rhel5.x86_64.rpm 
ERROR: 1062  Duplicate entry 'localhost-' for key 1
080211 13:54:13 [ERROR] Aborting

080211 13:54:13 [Note] /usr/sbin/mysqld: Shutdown complete

Installation of system tables failed!

Examine the logs in /var/lib/mysql for more information.
You can try to start the mysqld daemon with:
/usr/sbin/mysqld --skip-grant &
and use the command line tool
/usr/bin/mysql to connect to the mysql
database and look at the grant tables:

shell> /usr/bin/mysql -u root mysql
mysql> show tables

Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /var/lib/mysql that may be helpful.

The latest information about MySQL is available on the web at
http://www.mysql.com
Please consult the MySQL manual section: 'Problems running mysql_install_db',
and the manual section that describes problems on your OS.
Another information source is the MySQL email archive.
Please check all of the above before mailing us!
And if you do mail us, you MUST use the /usr/bin/mysqlbug script!
Starting MySQL....[  OK  ]
Giving mysqld 2 seconds to start

Suggested fix:
Perhaps use REPLACE instead of INSERT?
[11 Feb 2008 15:36] Johan Idrén
Workaround: Temporarily change the hostname to something other than 'localhost' while installing.
[20 Feb 2009 18:48] Joerg Bruehe
IMO, this is "Not a bug".

Reason:
Setting a host name to "localhost" may be technically possible, but is bound to create confusion.
It is technically sound to assume "localhost" is a special string which will not be used as a host name, so the server may well treat it special in its privilege checks (login, ...).
As a consequence of the above, our install scripts then need not protect against "duplicate key" for this.

Hence, I propose "Not a bug", and would like to see this checked.
[20 Feb 2009 18:51] Daniel Fischer
Agree with Jörg. This is not a bug. "localhost" is a reserved top-level domain name as per RFC 2606.