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

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

问题描述

我有一个问题,使用phpMyAdmin创建和栅格权限的用户。我有一个Java swing应用程序,它需要连接到此数据库。



我如何创建用户并授予权限,如下,一步一步。 >


  1. 打开phpMyAdmin

  2. 转到用户标签。

  3. 点击添加新用户

  4. 输入用户名,选择 Any Host 作为主机(所以%显示在其文本框中),并提及密码。 任何主机是因为需要远程访问。

  5. 选择 c $ c>全局特权 - 数据

  6. 单击 code>

  7. 现在我在用户标签的开始页。

  8. 点击我新创建的用户的编辑权限

  9. code>数据库特定

  10. 下选择所有数据库特定的权限,<$

  11. 点击 Go
  12. / ol>

    现在,每当我的Java应用程序连接到这个,它会给出以下错误

      java.sql.SQLException:拒绝访问用户'userName'@'localhost'(使用密码:YES)

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

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

    这里,对于变量 ip 尝试了 localhost 127.0.0.1 ,但仍然没有好。我做错了什么?



    我注意到如果我选择 Localhost 而不是任何主机

    $

    解决方案


    • 使您的用户。

    • 点击修改权限。

    • 更改任何主机的本地主机。



    • 滚动到底部,

    • 确保保留旧密码并按Go。


    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. 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

    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)
    

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

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

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

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

    解决方案

    • After you have made your user.
    • Click edit priviliges.
    • Change Any Host for Localhost.
    • Apply your priviliges.
    • Scroll to the bottom and
    • make sure that "keep old one" is selected and press Go.

    这篇关于MySQL:拒绝访问用户'userName'@'localhost'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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