error select command denied to user useridip address for table table

error select command denied to user useridip address for table table  using -'mysql,mysqldatareader,mysql-error-1142'

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, I get the following Error.

select command denied to user ''@'' for table ''

What could be wrong?

Please Help and Suggest.


Below is the code where I get that error. I tried debugging and found that it fails at the line

MySqlDataReader result1 = command1.ExecuteReader();

        String addSQL = "Select Max(`TradeID`) from `jsontest`.`tbl_Positions";
        MySqlConnection objMyCon = new MySqlConnection(strProvider);
        MySqlCommand command = objMyCon.CreateCommand();

        command.CommandText = addSQL;
         MySqlDataReader result = command.ExecuteReader();
        //int j = command.ExecuteNonQuery();
         while (result.Read())
             MaxTradeID = Convert.ToInt32(result[0]);
        for (i = 1; i <= MaxTradeID; i++)
            String newSQL = "Select `Strike`,`LongShort`,`Current`,`TPLevel`,`SLLevel` from `json`.`tbl_Position` where `TradeID` = '" + i + "'";
            MySqlConnection objMyCon1 = new MySqlConnection(strProvider);
            MySqlCommand command1 = objMyCon1.CreateCommand();

            command1.CommandText = newSQL;
            MySqlDataReader result1 = command1.ExecuteReader();


asked Sep 29, 2015 by deepak
0 votes

8 Answers

0 votes

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

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?

answered Sep 29, 2015 by bhavin
0 votes

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: ''

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

Hope this helps someone.

answered Sep 29, 2015 by okesh.badhiye
0 votes

You need to grant SELECT permissions to the MySQL user who is connecting to MySQL. See:

answered Sep 29, 2015 by jekbishnoi
0 votes

The problem is most probably between a . and a _. Say in my query I put


instead of


So I think MySQL would think LOCATION as a database name and was giving access privilege error.

answered Sep 29, 2015 by akasati02
0 votes

I had the exact same error message doing a database export via Sequel Pro on a mac. I was the root user so i knew it wasn't permissions. Then i tried it with mysqldump and got a different error message: Got error: 1449: The user specified as a definer ('joey'@'') does not exist when using LOCK TABLES

Ahh, I had restored this database from a backup on the dev site and I hadn't created that user on this machine. "grant all on . to 'joey'@'' identified by 'joeypass'; " did the trick.


answered Sep 29, 2015 by r3tt
0 votes

if you are working from a windows forms application this worked for me "server=localhost; user id=dbuser; password=password; database=dbname; Use Procedure Bodies=false;"

just add the "Use Procedure Bodies=false" at the end of your conection string.

answered Sep 29, 2015 by rajesh
0 votes

Similar to other answers I had miss typed the query.

I had -

SELECT FROM t.table LEFT JOIN table2 AS t2 ON = t2.table_id

Should have been

SELECT FROM table AS t LEFT JOIN table2 AS t2 ON = t2.table_id

Mysql was trying to find a database called t which the user didn't have permission for.

answered Sep 29, 2015 by ashish singh
0 votes

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

answered Sep 29, 2015 by jekbishnoi