[英]Access denied to mySQL database using PHP
So I've been trying to solve this problem for a couple of hours now. 因此,我已经尝试解决这个问题几个小时了。 And I have to make something clear. 我必须弄清楚一点。
mysql -u root mysql -u root
Now my code online is pretty simple. 现在我的在线代码非常简单。 It is PHP calling the mysqli 是PHP调用mysqli
<?php
$database = "myDatabase";
// Create new connection
$conn = new mysqli("localhost", "root", "", $database);
if ($conn -> connect_error) {
die ("Something went wrong: " . $conn -> connect_error);
} else {
echo "It works";
}
?>
Now I always get the error code 现在我总是得到错误代码
Something went wrong: Access denied for user 'root'@'localhost' (using password: NO) 发生问题:用户'root'@'localhost'的访问被拒绝(使用密码:NO)
If I could get any help that would be greatly appreaciated. 如果我能得到任何帮助,将不胜感激。 I've already tried to grant access but I think I'm doing it wrong. 我已经尝试授予访问权限,但我认为我做错了。
mysqli_connect
may be interpreting the empty password as no password at all mysqli_connect
可能会将空密码解释为根本没有密码
using password: NO 使用密码:否
Either try to set a password for the root
user, or create a new user with a password. 尝试为root
用户设置密码,或使用密码创建新用户。 And via Tripp Kinetics comment, make sure the permissions are set properly for the new user. 并通过Tripp Kinetics注释,确保为新用户正确设置权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.