用户root @ localhost的访问被拒绝 [英] access denied for user root @ localhost
问题描述
我正在尝试连接到mysql,但是它给出了警告 mysqli_connect():(HY000/1045):拒绝用户'root'@'localhost'的访问(使用密码:是) 我认为用户名和密码是正确的,因为我可以在komand行中访问mysql.我还创建了另一个用户,并授予他所有特权,但我仍然收到此警告.
i am trying to connect to mysql,but it gives a warning mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) .I think the username and password is correct,because i have access to mysql in komand line.I also created another user and granted him all priveleges but still i have this warning.
我可以访问phpMyAdmin.我正在使用wamp服务器(apache 2.4.9)和mysql 5.1
I have access to phpMyAdmin.I am using wamp server(apache 2.4.9) and mysql 5.1
<?php
$conn = mysqli_connect("localhost", "root", "password");
?>
推荐答案
如果用户存在并且blahblah
暂时不重要,以下两行将失败:
Let the following 2 lines fail if user exists and blahblah
doesnt matter for now:
create user 'root'@'localhost' identified by 'blahblah';
create user 'root'@'127.0.0.1' identified by 'blahblah';
进行补助:
grant all on *.* to 'root'@'localhost';
grant all on *.* to 'root'@'127.0.0.1';
将密码更改为您会记住的密码:
Change the password to something you will remember:
set password for 'root'@'localhost' = password('NewPassword');
set password for 'root'@'127.0.0.1' = password('NewPassword');
查看您拥有多少个root用户.真实用户是用户/主机组合.密码将显示为散列:
See how many root users you have. A real user is a user/host combo. The password will show up hashed:
select user,host,password from mysql.user where user='root';
或
select user,host,authentication_string from mysql.user where user='root';
上面的第二个用于MySQL 5.7
The 2nd one above is for MySQL 5.7
如果您获得的不仅仅是上述两个用户,请删除其他用户,例如:
If you get more than the two users above, drop the others such as:
drop user 'root'@'%'; -- this is the wildcard hostname, can be a security risk
drop user 'root'@'::1';
仍然只有2个吗?但愿如此.使用上面的选择语句进行检查.
Still have only 2? I hope so. Use the select stmts above to check.
请勿使用root连接用户应用. root仅用于维护.不管是服务器端代码还是管理员正在运行它.没有安全保护和/或注入有害语句的代码将以root身份运行. 所以,这就是为什么.
Don't connect a user app using root. root is for maintenance only. It doesn't matter if it is server-side code, or if an admin is running it. Code that is not secured and/or injected with harmful statements gets to run as root. So there, that is why.
这篇关于用户root @ localhost的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!