Home > Database > Mysql Tutorial > body text

mysql新建用户本地无法登录_MySQL

WBOY
Release: 2016-06-01 13:32:14
Original
1028 people have browsed it

bitsCN.com

mysql新建用户本地无法登录

 

出此是用mysql,因为root权限过高,所以新建一用户appadmin,权限仅为要用到的数据库。创建语句如下:grant select,insert,update,delete on test.* to appadmin@"%" identified by "password";其中@“%”是可以在任何地址登录。 

创建后到mysql.user下查看,有该用户。但是使用mysql -u appadmin -ppassword 登录,提示无法登录:ERROR 1045 (28000): Access denied for user 'appadmin'@'localhost' (using password: YES) 

 

百思不得其解,遂google,其中有人说到“mysql.user 表中有另外一些记录产生了作用,最有可能的就是已经有一条''@localhost记录,就是用户名是空,主机字段是localhost的记录。” 影响了。查看该表果然有。 

mysql> select host,user,password from mysql.user; +-----------+------------------+-------------------------------------------+ | host      | user             | password                                  | +-----------+------------------+-------------------------------------------+ | localhost | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | mza       | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | 127.0.0.1 | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | localhost |                  |                                           | | mza       |                  |                                           | | localhost | debian-sys-maint | *19DF6BF8310D46D681AE072AB73ECEC99C018C19 | | %         | appadmin         | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | +-----------+------------------+-------------------------------------------+ 7 rows in set (0.00 sec) 
Copy after login

 

但是删除那些为空(匿名)的用户后仍然无法登录。(可能是因为没有重启mysql)于是只好耐着性子看mysql参考手册。发现其中增加用户部分有这么一段话: 

其中两个账户有相同的用户名monty和密码some_pass。两个账户均为超级用户账户,具有完全的权限可以做任何事情。一个账户 ('monty'@'localhost')只用于从本机连接时。另一个账户('monty'@'%')可用于从其它主机连接。请注意monty的两个账户必须能从任何主机以monty连接。没有localhost账户,当monty从本机连接时,mysql_install_db创建的localhost的匿名用户账户将占先。结果是,monty将被视为匿名用户。原因是匿名用户账户的Host列值比'monty'@'%'账户更具体,这样在user表排序顺序中排在前面。 

这段话说的很清楚,因此执行 grant select,insert,update,delete on test.* to appadmin@"localhost" identified by "password"; 

退出后用appadmin登录,成功。
 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!