12Apr
或许今年真的有些不顺……连安装下MySQL都给我出问题……
root@localhost:/usr/local/mysql# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...
ERROR: 1062 Duplicate entry 'localhost-' for key 1
080411 14:38:09 [ERROR] Aborting
080411 14:38:09 [Note] ./bin/mysqld: Shutdown complete
Installation of system tables failed!
Installing MySQL system tables...
ERROR: 1062 Duplicate entry 'localhost-' for key 1
080411 14:38:09 [ERROR] Aborting
080411 14:38:09 [Note] ./bin/mysqld: Shutdown complete
Installation of system tables failed!
查看下 scripts/mysql_install_db 脚本,发现安装时调用的建立系统表的SQL文件是下面这个:share/mysql_system_tables_data.sql
-- Fill "users" table with default users allowing root access
-- from local machine if "users" table didn't exist before
CREATE TEMPORARY TABLE tmp_user LIKE user;
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;
-- from local machine if "users" table didn't exist before
CREATE TEMPORARY TABLE tmp_user LIKE user;
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;
这下找到问题所在了,我的系统主机名默认 localhost,应此插入时导致重复。
解决办法:
1、更改主机名
2、修改上面这段SQL脚本
INSERT INTO tmp_user (host,user) VALUES (@@hostname,'');
更改为:
REPLACE INTO tmp_user (host,user) VALUES (@@hostname,'');
OK ……

Leave a reply