首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >即使不提供密码也可以登录Mysql

问即使不提供密码也可以登录Mysql
EN

Stack Overflow用户
提问于 2013-10-26 15:49:59
回答 5查看 20.2K关注 0票数 7

mysql在登录时的提示甚至不提供密码,如果提供了像mysql -u root -p一样的提示输入密码,如果提供了像mysql -u root这样的提示,则在不询问密码的情况下登录,我已经运行了查询

代码语言:javascript
复制
select user,hosts from mysql.user; 

并了解到有3个root用户具有不同的主机,如下所示

代码语言:javascript
复制
+------+-------------+
| user | host        |
+------+-------------+
| root | 127.0.0.1   |
| root | db-busindia |
| root | localhost   |
+------+-------------+

有趣的是mysql服务器名也是db-busindia,root@'db-busindia'是罪魁祸首吗?

EN

回答 5

Stack Overflow用户

发布于 2013-10-26 16:49:05

检查my.cnf文件的客户机节中的行:

代码语言:javascript
复制
user=root 
password=some text.

这使您可以在没有用户名或密码的情况下登录。如果希望系统提示您输入密码,请删除password行。

票数 3
EN

Stack Overflow用户

发布于 2020-02-27 20:35:57

是的,就连我也很久以前就遇到过这个问题。我们通常会在安装MySQL服务器时遇到它们,所有的客户端连接都是使用套接字建立连接的。您可以简单地在mysql.user表中查看它的插件。

代码语言:javascript
复制
Ubuntu@localhost:~# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User             | Host      | plugin                |
+------------------+-----------+-----------------------+
| root             | localhost | auth_socket           |
| mysql.session    | localhost | mysql_native_password |
| mysql.sys        | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+

mysql> update mysql.user set plugin='mysql_native_password' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

您可以通过将插件值更新为“mysql_native_password”来禁用该选项。

代码语言:javascript
复制
Ubuntu@localhost:~# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Ubuntu@localhost:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
票数 2
EN

Stack Overflow用户

发布于 2013-11-26 20:09:07

MySQL允许我们在不传递user和password的情况下登录,只需将user和password放入my.cnf即可。

代码语言:javascript
复制
$ mysql

请检查通常在/etc/mysql/中的my.cnf,或者如果您有覆盖,您可以在~/.my.cnf中找到它。只要删除user和password即可。

可以看到类似下面这样的内容:

代码语言:javascript
复制
user=root
password=35620fhgf8025ec31ffd2c1
host=127.0.0.1
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19604324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档