MySQL:用户“userName"@“localhost"的访问被拒绝 [英] MySQL: Access denied for user 'userName'@'localhost'

查看:55
本文介绍了MySQL:用户“userName"@“localhost"的访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 phpMyAdmin 创建和授予用户权限时遇到问题.我有一个 Java Swing 应用程序,它需要连接到这个数据库.

I am having an issue with creating and grating permissions to a user using phpMyAdmin. I am having a Java swing application and it need to connect to this database.

我如何创建用户并授予权限的步骤如下.

How I created the user and granted the permission are below, step by step.

  1. 打开 phpMyAdmin
  2. 转到用户"标签.
  3. 点击添加新用户
  4. 提供用户名,选择 Any Host 作为主机(因此 % 显示在其文本框中),并提及密码.任何主机都是因为需要远程访问.
  5. 选择Global Privileges下的Select - Data
  6. 点击Go
  7. 现在我又回到了 Users 标签页的起始页.
  8. 点击我新创建的用户的Edit Privileges.
  9. Database-specific privileges
  10. 下选择数据库
  11. 勾选Database-specific privilegesData 部分下的所有内容.
  12. 点击Go
  1. Open phpMyAdmin
  2. Go to 'Users' tab.
  3. Click on Add New User
  4. Give the user name, select Any Host as the host (so the % is displayed in its text box), and mention the password. Any host is because remote access required.
  5. Select Select under Global Privileges - Data
  6. Click on Go
  7. Now I am in the Users tab starting page again.
  8. Click on Edit Privileges on my newly created user.
  9. Select the database under Database-specific privileges
  10. Tick everything under Database-specific privileges, Data section.
  11. Click on Go

现在,每当我的 Java 应用程序连接到此时,都会出现以下错误

Now, whenever my Java application connects to this, it gives the below error

java.sql.SQLException: Access denied for user 'userName'@'localhost' (using password: YES)

这就是我在 Java 应用程序中连接到数据库的方式

This is how I connect to the database, in my Java application

con = DriverManager.getConnection("jdbc:mysql://"+ip+":3306/databaseName","user","password");

这里,对于变量 ip,我尝试了 localhost127.0.0.1 但仍然不行.我做错了什么?

Here,for the variable ip, I tried both localhost and 127.0.0.1 but still no good. What have I done wrong?

我注意到,如果我在步骤 4 中选择 Localhost 而不是 Any Host,连接工作正常.

I noticed the connection works fine if I select Localhost instead of Any Host in step 4.

推荐答案

  • 在您创建用户之后.
  • 点击编辑权限.
  • 将任何主机更改为本地主机.
  • 应用您的特权.
  • 滚动到底部和
  • 确保选中保留旧的",然后按执行".
  • 这篇关于MySQL:用户“userName"@“localhost"的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆