简体   繁体   English

MySQL Web用户权限访问被拒绝

[英]MySQL Web User permissions Access denied

I am trying to create a web user account for MySQL, but haven't able to get it working right. 我正在尝试为MySQL创建一个Web用户帐户,但无法使其正常运行。 My user is webusr with password WebUser and the database is books . 我的用户是webusr ,密码为WebUser ,数据库是book

I created the user in phpMyAdmin with SELECT, INSERT, and UPDATE only. 我仅使用SELECT,INSERT和UPDATE在phpMyAdmin中创建了用户。 When I run my PHP line $db = new mysqli('localhost', 'webusr', 'WebUser', 'books'); 当我运行我的PHP行时, $db = new mysqli('localhost', 'webusr', 'WebUser', 'books'); it fails with the message “Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'webusr'@'localhost' (using password: YES)” 它失败并显示消息“Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'webusr'@'localhost' (using password: YES)”

phpMyAdmin phpMyAdmin2

Not sure what I am doing wrong here. 不知道我在做什么错。 The Database also has the same permissions setup. 数据库也具有相同的权限设置。 I am on a Windows PC using EasyPHP. 我在使用EasyPHP的Windows PC上。 I tried the setup with the root user without password and the code seems to work fine. 我用没有密码的root用户尝试了安装,该代码似乎正常工作。

1: Try using PDO instead of mySQLi Why bother using PDO? 1:尝试使用PDO而不是mySQLi 为什么还要使用PDO? click to read. 点击阅读。
2: For now, try this: 2:目前,请尝试以下操作:

 $db = new mysqli('localhost', 'webusr', 'WebUser', 'books'); 

instead of this: 代替这个:

 $db = new mysqli('localhost', webusr, WebUser, books); 

Most likely you're not matching the host field. 您很可能与主机字段不匹配。 In MySQL, the wildcard host % does not match socket connections, for those you need the host localhost , and if I recall correctly some versions don't even match 127.0.0.1 to % . 在MySQL中,wildcard宿主%不匹配套接字连接,对于那些需要在主机localhost ,如果我没有记错的一些版本不匹配,甚至到127.0.0.1 %

Since you're telling mysqli to use socket connections (by connecting to host localhost), and your user host field is not 'localhost', you're not able to connect. 由于您告诉mysqli使用套接字连接(通过连接到主机localhost),并且您的用户主机字段不是'localhost',因此您将无法连接。 Edit your existing user and change the host to 'localhost' if you don't need tcp connections or add a new user with host 'localhost' if you want to continue to allow tcp connections (for instance, if you have an application on a different machine). 编辑现有用户,如果不需要tcp连接,则将主机更改为“ localhost”;如果要继续允许tcp连接(例如,如果在Windows上有一个应用程序,则将其添加为主机为“ localhost”的新用户)不同的机器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM