300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 为什么mysql设置了密码之后 不需要输入密码就可以登录数据库了?

为什么mysql设置了密码之后 不需要输入密码就可以登录数据库了?

时间:2019-02-20 13:40:57

相关推荐

为什么mysql设置了密码之后 不需要输入密码就可以登录数据库了?

CentOS安装mysql之后,之前设置了密码,但输入mysql -u -p后,会直接进入mysql,而输入mysql -uroot -p,则需要输入密码,这是为什么呢?

[root@hadoop01 ~]# mysql -u -pWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 11Server version: 5.1.73 Source distributionCopyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye[root@hadoop01 ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 12Server version: 5.1.73 Source distributionCopyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

通过查找资料,原来是因为数据库里面有空用户。

解决方法如下:

进入mysql输入:

select * from mysql.user where user='';

mysql> select * from mysql.user where user='';+-----------+------+----------+-------------+-------------+-------------+-------------+----------------+-----------+------------+-----------------+------------+------------+--------------+----------------+-----------------+------------------+------------------+----------------+--------------------+--------------+----------+------------+-------------+--------------+---------------+-----| Host| User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_pr_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Supercute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routit_priv | Trigger_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_+-----------+------+----------+-------------+-------------+-------------+-------------+----------------+-----------+------------+-----------------+------------+------------+--------------+----------------+-----------------+------------------+------------------+----------------+--------------------+--------------+----------+------------+-------------+--------------+---------------+-----| localhost ||| N | N | N | N | N | N | N| N| N| N| N | N | N| N| N| N | N | N || | | | 0 || hadoop01 ||| N | N | N | N | N | N | N| N| N| N| N | N | N| N| N| N | N | N || | | | 0 |+-----------+------+----------+-------------+-------------+-------------+-------------+----------------+-----------+------------+-----------------+------------+------------+--------------+----------------+-----------------+------------------+------------------+----------------+--------------------+--------------+----------+------------+-------------+--------------+---------------+-----2 rows in set (0.00 sec)

查询有结果,然后进行下一步。

use mysql;

delete from user where user = '';

mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> delete from user where user = '';Query OK, 2 rows affected (0.00 sec)

删除了多余的空白账户, 然后进行下一步。

flush privileges;­

mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

重载一次权限表,最后用

service mysqld restart

[root@hadoop01 ~]# service mysqld restartStopping mysqld: [ OK ]Starting mysqld: [ OK ]

重启mysql服务,问题得到解决,

[root@hadoop01 ~]# mysql -u -pERROR 1045 (28000): Access denied for user '-p'@'localhost' (using password: NO)[root@hadoop01 ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quit;Bye

注意:

1、一定要记住重启mysql服务,否则不会生效。

2、msyql的用户表在mysql数据库中的user表中,主要字段有host,user,password等,作为mysql用的管理的主要表。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。