localhost ~ # mysql_install_db
Installing MySQL system tables...
091101 11:27:35 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
091101 11:27:35 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
Installation of system tables failed!
关闭mysqld,启动mysqld_safe:
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
然后登录:
mysql mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
17 rows in set (0.01 sec)
可以通过
mysql> select * from user;
Empty set (0.00 sec)mysql> INSERT INTO user (Host,User,Password)
-> VALUES('localhost','root','');
添加用户,但是怎样设置root用户的最高权限?
因为此时GRANT ALL PRIVILEGES无权运行。
-----------------------------------------------------------------------------------------------------------
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!
查看下 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;
这下找到问题所在了,我的系统主机名默认 localhost,应此插入时导致重复。
解决办法:
1、更改主机名
2、修改上面这段SQL脚本
INSERT INTO tmp_user (host,user) VALUES (@@hostname,''); 更改为:
REPLACE INTO tmp_user (host,user) VALUES (@@hostname,''); 或更改主机名,不为localhost
OK ……
需要注意的是,这个问题我在fedora和suse以及freebsd下均未发现,仅是在gentoo下有此问题。其他版本的系统不保证该方法有效~~~~