简体   繁体   English

无法访问数据库,拒绝用户访问

[英]Can't access database, access denied for user

I got this error message while connecting my app with the database at my website. 将我的应用程序与网站上的数据库连接时收到此错误消息。 If i try using XAMPP using my computer, its work well. 如果我尝试在计算机上使用XAMPP,则其效果很好。

FYI, the username and password is same as username and password that i created using XAMPP. 仅供参考,用户名和密码与我使用XAMPP创建的用户名和密码相同。 and also grant the privileges. 并授予特权。

this is the connection string. 这是连接字符串。 for example the server is 174.125.80.140, the database name is myDB, the Uid is alfred, and the password is Alfred111. 例如,服务器为174.125.80.140,数据库名称为myDB,Uid为alfred,密码为Alfred111。

MySqlConnection conn = new MySqlConnection("Server=174.125.80.140; Database=myDB;Uid=alfred;Pwd=Alfred111;");

I'm using MySQL client version: 4.1.22. 我正在使用MySQL客户端版本:4.1.22。 I'm still can't access the database. 我仍然无法访问数据库。 is there any solution?? 有什么解决办法吗?

If you are using MySQL workbench, 1) Start the workbench 2) click on the option "Users and Privileges" under SECURITY 3) click on add user (for the specific user), this is more secure because it lets you handle who has access over your database and lets you control access. 如果您使用的是MySQL工作台,则1)启动工作台2)单击“安全”下的“用户和特权”选项3)单击“添加用户”(针对特定用户),因为它可以让您处理有权访问的用户,所以这是更安全的在数据库上,让您控制访问。

however if you want to grant access a large number of users for an application like c# application, then hard-code the username and password in the application, from the user privileges that you have set above. 但是,如果您想为诸如c#应用程序之类的应用程序授予大量用户访问权限,则可以使用上面设置的用户权限在应用程序中对用户名和密码进行硬编码。

Hope this helps (^_^) 希望这会有所帮助(^_^)

Yes, you may have supplied the user and password correctly but have you configure the server ( new server ) to accept Uid=alfred;Pwd=Alfred111; 是的,您可能已经正确提供了用户名和密码,但是您已将服务器( 新服务器 )配置为接受Uid=alfred;Pwd=Alfred111; ?

Adding User in MySQL Server 在MySQL服务器中添加用户

If your app is on a different host that the MySQL server then you most likely need to add a new user granting permission for that host. 如果您的应用程序位于与MySQL服务器不同的主机上,则您很可能需要添加新用户授予该主机的权限。 Your alfred user is probably allowed by localhost and nothing else. 您的alfred用户可能是localhost允许的,别无其他。 Try CREATE USER 'altred@'%' identified by 'password'; 尝试CREATE USER 'altred@'%' identified by 'password'; and then grant that user privileges on myDB . 然后在myDB上授予该用户特权。

You can replace % with a specific IP address or hostname as well, % allows the connection from any host which is not necessarily safe. 您也可以用特定的IP地址或主机名替换%%允许来自不一定安全的任何主机的连接。

You can try the following query to see the allowed user/host combos: 您可以尝试以下查询以查看允许的用户/主机组合:

SELECT `User`, `Host` FROM `mysql.user`

Hope that helps. 希望能有所帮助。

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

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