Bug #92278 Failed to fetch table privileges for particular user via getTablePriviliges()
Submitted: 4 Sep 2018 5:07 Modified: 6 Sep 2018 4:51
Reporter: Charchit Patodi Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[4 Sep 2018 5:07] Charchit Patodi
Description:
While executing getTablePrivileges() JDBC API, I am getting below exception -

/*Exception*/
Exception in thread "main" java.sql.SQLSyntaxErrorException: SELECT command denied to user 'userb'@'10.80.112.32' for table 'tables_priv'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:975)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1025)
	at com.mysql.cj.jdbc.DatabaseMetaData.getTablePrivileges(DatabaseMetaData.java:3533)
	at userPermissionTest_OCON7049.userPermission.showPrivliges(userPermission.java:101)
	at userPermissionTest_OCON7049.userPermission.main(userPermission.java:22)
/*Exception*/

My query is -
 Is there any way to resolve this and get the table privilege details in MySQL ?
 Is there any other way to to fetch table privileges from MySQL Database ?

Driver Name - MySQL Connector/J
Driver Version - mysql-connector-java-8.0.12 (Revision: 24766725dc6e017025532146d94c6e6c488fb8f1)

How to repeat:
Call out getTablePrivileges(catalog, schema, table) JDBC API from simple java program.
[5 Sep 2018 13:02] MySQL Verification Team
Hello Charchit,

We're sorry, but the bug system is not the appropriate forum for asking help on using MySQL products. Your problem is not the result of a bug.

Imho this is not a bug,  if you see the error message i.e "SELECT command denied to user 'userb'@'10.80.112.32' for table 'tables_priv'" - it is pretty clear that 'userb' don't have select privileges on mysql.tables_priv table.  I suggest you either add this privileges to user or try with another user which has these permissions.

Support on using our products is available both free in our forums at http://forums.mysql.com/ and for a reasonable fee direct from our skilled support engineers at http://www.mysql.com/support/

Thank you for your interest in MySQL.

regards,
Umesh
[6 Sep 2018 4:51] Charchit Patodi
Hi Umesh,

Could you please help in how to give permission to users. As getTablePrivileges() is JDBC API, it is working with other databases but only failing in case of MySQL. Could you please check why this JDBC API is failing to fetch result.

As we already tried with different users but for all it got failed. we also tried with "root" user but even root did not succeed. We also tried to give permission to various user to this table but that also failed.

Thanks and Regards,
Charchit Patodi.