Error: select command denied to user ''@'' for table ''
前端 未结 14 1416
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 16:30

In my website, I am using MySQL database. I am using a webservice where in I do all my database related manipulations.

Now In one of the methods of that webservice,

相关标签:
14条回答
  • 2020-11-27 16:49

    I had the same problem. I was very frustrating with it. Maybe this is not answering the question, but I just want to share my error experience, and there may be others who suffered like me. Evidently it was just my low accuracy.

    I had this:

    SELECT t_comment.username,a.email FROM t_comment
    LEFT JOIN (
        SELECT username,email FROM t_un
    ) a
    ON t_comment.username,a.email
    

    which is supposed to be like this:

    SELECT t_comment.username,a.email FROM t_comment
    LEFT JOIN (
        SELECT username,email FROM t_un
    ) a
    ON t_comment.username=a.username
    

    Then my problem was resolved on that day, I'd been struggled in two hours, just for this issue.

    0 讨论(0)
  • 2020-11-27 16:50

    This problem happened to me because I had the hibernate.default_schema set to a different database than the one in the DataSource.

    Being strict on my mysql user permissions, when hibernate tried to query a table it queried the one in the hibernate.default_schema database for which the user had no permissions.

    Its unfortunate that mysql does not correctly specify the database in this error message, as that would've cleared things up straight away.

    0 讨论(0)
  • 2020-11-27 16:50

    A bit late to the party but, should you have root access, you can do the following directly:

    Log into your mysql as root,

    $ mysql -u root -p
    

    Show databases;

    mysql>SHOW DATABASES;
    

    Select mysql database, which is where all privileges info is located

    mysql>USE mysql;
    

    Show tables.

    mysql>SHOW TABLES;
    

    The table concerning privileges for your case is 'db', so let's see what columns it has:

    mysql>DESC db;
    

    In order to list the users privileges, type the following command, for example:

    mysql>SELECT user, host, db, Select_priv, Insert_priv, Update_priv, Delete_priv FROM db ORDER BY user, db;
    

    If you can't find that user or if you see that that user has a 'N' in the Select_priv column, then you have to either INSERT or UPDATE accordingly:

    INSERT:

    INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv) VALUES ('localhost','DBname','UserName','Y' ,'N','N','N');
    

    UPDATE:

    UPDATE db SET Select_priv = 'Y' WHERE User = 'UserName' AND Db = 'DBname' AND Host='localhost';
    

    Finally, type the following command:

    mysql>FLUSH PRIVILEGES;
    

    Ciao.

    0 讨论(0)
  • 2020-11-27 16:52

    I had the same problem. This is related to hibernate. I changed the database from dev to production in hibernate.cfg.xml but there were catalog attribute in other hbm.xml files with the old database name and it was causing the issue.

    Instead of telling incorrect database name, it showed Permission denied error.

    So make sure to change the database name everywhere or just remove the catalog attribute

    0 讨论(0)
  • 2020-11-27 16:54

    database user does not have the permission to do select query.

    you can grant the permission to the user if you have root access to mysql

    http://dev.mysql.com/doc/refman/5.1/en/grant.html

    Your second query is on different database on different table.

     String newSQL = "Select `Strike`,`LongShort`,`Current`,`TPLevel`,`SLLevel` from `json`.`tbl_Position` where `TradeID` = '" + i + "'";
    

    And the user you are connecting with does not have permission to access data from this database or this particular table.

    Have you consider this thing?

    0 讨论(0)
  • 2020-11-27 16:54

    I'm sure the original poster's issue has long since been resolved. However, I had this same issue, so I thought I'd explain what was causing this problem for me.

    I was doing a union query with two tables -- 'foo' and 'foo_bar'. However, in my SQL statement, I had a typo: 'foo.bar'

    So, instead of telling me that the 'foo.bar' table doesn't exist, the error message indicates that the command was denied -- as though I don't have permissions.

    Hope this helps someone.

    0 讨论(0)
提交回复
热议问题