Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT command denied to user 'user'@'localhost' for table 'table'

I have deployed my database on MySQL Database server. I have a user 'bedgeaj_root@localhost' and it has all the permissions. But it still giving me the error :

SELECT command denied to user 'bedgeaj_root'@'localhost' for table 'transactions'

While searching on the net, I studied that it is some user permission issue. But I don't understand that why it is giving this error as I have given all the permission to this user.

Here is the screen shot of my cPanel user permissions screen:

bedgeaj_root@localhost permissions screen

Here goes my stack trace:

   Caused by: net.sf.jasperreports.engine.JRException: Error executing SQL statement for : itemizedStatementReport_patientBalance
at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:246)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1073)
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:667)
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1235)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:859)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:804)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:652)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59)
at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:205)
... 1 more


   Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'bedgeaj_root'@'localhost' for table 'transactions'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.Util.getInstance(Util.java:382)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281)
at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:239)
... 9 more

I am using this query:

    SELECT alias.patient_id , SUM(alias.balance) AS balance
    from (
    SELECT v.patient_id,trx.trx_id,trx.trx_status,trx.trx_seq,pb.billing_id,v.visit_id,v.visit_dt,forma t(SUM(tl.net_amount) - ifnull((SELECT SUM(pl.applied_amount+pl.discount_amount) FROM payment_lines pl where pl.trx_line_id = tl.trx_line_id),0.0),2)AS balance
    FROM ((transactions trx JOIN trx_lines tl ON (trx.trx_id = tl.trx_id))JOIN patient_billing pb ON(pb.billing_id = trx.billing_id))JOIN visits v ON (pb.visit_id = v.visit_id)
    where trx.trx_seq='4' AND trx.trx_status='PENDING' AND (date_format(v.visit_dt,'%Y/%m/%d')<date_format(DATE_SUB(NOW(), INTERVAL 1 day),'%Y/%m/%d'))
    group by tl.trx_id) alias
    where alias.patient_id = $P{patient_id}

group by alias.patient_id]

What I am doing wrong?

like image 511
Muhammad Salman Farooq Avatar asked Aug 06 '13 10:08

Muhammad Salman Farooq


People also ask

How do I add user privileges in MySQL?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';


3 Answers

grant all privileges on bedgeaj_medmax.transactions to 'bedgeaj_root'@'%'  identified by 'password';

Try this one.

EDIT

Error: select command denied to user '<userid>'@'<ip-address>' for table '<table-name>'

See comment by pisces in the above link.

like image 82
Mihai Avatar answered Nov 19 '22 01:11

Mihai


I had a similar issue. My local database was created from a dump from another server and the local server didn't have all the right permissions for a user that was on the dev server. I got this error trying to backup my local database using sequel pro. Then I tried mysqldump and got a different error: Got error: 1449: The user specified as a definer ('joey'@'127.0.0.1') does not exist when using LOCK TABLES . So I granted all on . to [email protected] and it fixed it.

like image 38
superaesomedad Avatar answered Nov 19 '22 02:11

superaesomedad


I had a similar problem.
In my situation, the error appeared because MySQL is case sensitive in Linux!

See this:

In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Triggers also correspond to files. Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database, table, and trigger names. This means such names are not case sensitive in Windows, but are case sensitive in most varieties of Unix.

If GRANT command was run before, changing tablename to TABLENAME/Tablename can solve the problem.

like image 1
ROMANIA_engineer Avatar answered Nov 19 '22 02:11

ROMANIA_engineer