简体   繁体   中英

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.

FYI, the username and password is same as username and password that i created using 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.

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

I'm using MySQL client version: 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.

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.

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; ?

Adding User in MySQL Server

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. Your alfred user is probably allowed by localhost and nothing else. Try CREATE USER 'altred@'%' identified by 'password'; and then grant that user privileges on myDB .

You can replace % with a specific IP address or hostname as well, % allows the connection from any host which is not necessarily safe.

You can try the following query to see the allowed user/host combos:

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

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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