没有提供密码时如何禁用MySQL根登录? [英] How to disable MySQL root logins when no password is supplied?
问题描述
MySQL已安装在我的笔记本电脑上,并且可以正常运行,但允许我在不提供root密码的情况下登录.我也可以通过提供root密码登录.如果提供的密码不匹配,则拒绝访问.最初安装MySQL时,root密码已更改为我自己选择的密码.我刚刚注意到今天没有密码登录.
MySQL is installed on my laptop and it works fine, except that I am allowed to log in without supplying the root password. I can also log in by supplying the root password. If the supplied password doesn't match, it denies access. The root password was changed to something of my own choosing when I originally installed MySQL. I just noticed the no-password logins today.
因此,当没有提供密码时,我需要停止对root帐户的访问.到目前为止,我尝试过的操作是使用以下命令重置root密码:
So, I need to stop access to the root account when a password isn't supplied. What I've tried so far is to reset the root password with:
mysqladmin -u root password TopSecretPassword
然后我登录到控制台并发出:
I then logged in to the console and issued:
mysql> flush privileges; exit;
我仍然可以通过以下方式登录MySQL:
I'm still able to log in to MySQL with:
%> mysql -u {enter}
如何停止这种行为?
其他详细信息:
%> mysql -u {enter}
mysql>SELECT USER(), CURRENT_USER();
> root@localhost, root@localhost
mysql>SELECT COUNT(*) FROM mysql.users WHERE user='root' AND password='';
> COUNT(*)
> 0
mysql>SELECT COUNT(*) FROM mysql.users WHERE user='';
> COUNT(*)
> 0
mysql>SELECT COUNT(*) FROM mysql.users WHERE user='root';
> COUNT(*)
> 1
%> vi /etc/my.cnf
/skip-grant-tables
> E486: Pattern not found: skip-grant-tables
推荐答案
我知道这个问题已有几个月的历史了,但是我遇到了同样的问题.
I know this question is a few months old, but I had the same issue.
就我而言,这是由于〜/.my.cnf中存在一个包含用户和密码的特定于用户的配置文件.就我而言,cPanel创建了此配置文件.
In my case, it was due to the presence of a user-specific configuration file located at ~/.my.cnf that contained the user and password. In my case, cPanel created this config file.
[client]
pass="ROOT_PASSWORD_WAS_HERE!"
user=root
特定于用户的配置文件是MySQl的功能,并且在文档中详细介绍了读取的所有配置文件的位置:
User-specific configuration files are a feature of MySQl, and the location of all the config files read are detailed in the documentation: http://dev.mysql.com/doc/refman/5.1/en/option-files.html.
如果您正在* nix dist上运行mysql,请运行以下命令以查看您是否具有特定于用户的配置文件:
If you're running mysql on a *nix dist, run the following command to see if you have a user-specific config file:
cat ~/.my.cnf
这篇关于没有提供密码时如何禁用MySQL根登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!