[MySQL]
centos5安装 mysql 提示需要用户及密码进入?Duplicate entry 'localhost-' for key 1
数据库
发布于:2021-07-05 09:38
|
阅读数:417
|
评论:0
有朋友在centos 5 上安装mysql 一切正常,也能正常启动。就是无法进入mysql
提示 Duplicate entry 'localhost-' for key 1
需要用户名及密码,可是新安装的mysql是没有密码的,这是为什么?
今天帮朋友试验了一把解决了这个问题:
导致这个错误的原因:
因为安装系统时设置了hostname为localhost导致mysql在创建表的时候没有创建成功。因此mysql库中user表里没有root这个用户或者说root没有显示出来,无法查看root的状态。这时需要手动创建。然而在安全模式无法直接创建用户,错误见下。
变个方向就能创建了,先给root给予权限,然后刷新表。之后就可以创建了。
具体步骤见下。有朋友遇到此问题可以依此解决。
一、killall -TERM mysqld
以安全模式启动mysql
/usr/bin/mysqld_safe --skip-grant-tables &
进入mysql
/usr/bin/mysql
mysql> use mysql
Database changed
mysql> select * from user where user='root';
Empty set (0.00 sec)
mysql> grant all privileges on *.* to root@localhost identified by 'linuxtone' with GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute
this statement
mysql> update user set password=password('linuxtone') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
注意单双引号。
mysql> flush privileges; //注意先刷新下表
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to root@localhost identified by 'linuxtone' with GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where user='root';
+-----------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+-------
-----+-----------------+------------+------------+--------------+------------+-----------------------+---
---------------+--------------+-----------------+------------------+------------------+----------------+-
--------------------+--------------------+------------------+----------+------------+-------------+------
--------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv |
Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv |
Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv
| Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv
| Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer |
x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+-------
-----+-----------------+------------+------------+--------------+------------+-----------------------+---
---------------+--------------+-----------------+------------------+------------------+----------------+-
--------------------+--------------------+------------------+----------+------------+-------------+------
--------+---------------+-------------+-----------------+----------------------+
| localhost | root | *4F9DA9DB95483BFD192C7BF3DB0402555E89360D | 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 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+-------
-----+-----------------+------------+------------+--------------+------------+-----------------------+---
---------------+--------------+-----------------+------------------+------------------+----------------+-
--------------------+--------------------+------------------+----------+------------+-------------+------
--------+---------------+-------------+-----------------+----------------------+
1 row in set (0.00 sec)
后期处理:
/usr/local/mysql/bin/mysqladmin shutdown -uroot -p
刚才的密码
然后正常启动:/usr/bin/mysqld_safe &
/usr/local/mysql/bin/mysql -uroot -p
能正常登录!
官方文档
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
总结:我这叫总结么?我不知道为啥能成,不过大体就是root无法对库进行操作。select就能查出来。
然后在安全模式下无法授权,那只能升级下密码了。这时注意下刷新表。
然后再给root用户授权。这样就哦了。
有空的哥们也多研究下。
今早哥们netseek 解决了这个问题:
http://www.linuxtone.org/redirec ... o=lastpost#lastpost
最终解决办法::
Duplicate entry 'localhost-' for key 1 问题,很可能是你的主机名有问题,比如是localhost?
导致mysql 的root 帐号的三个主机值(分别是%、localhost、主机名)的后二者的名字弄成一样了,导使唯一键值出现重复而禁用该记录了?
朋友的主机名设置成了:localhost 遭成了Duplicate entry 'localhost-' for key 1
设置好正确的主机名仍后重新编译就可以了,朋友安装系统的时候没有注意主机名
免责声明:
1. 本站所有资源来自网络搜集或用户上传,仅作为参考不担保其准确性!
2. 本站内容仅供学习和交流使用,版权归原作者所有!© 查看更多
3. 如有内容侵害到您,请联系我们尽快删除,邮箱:kf@codeae.com