select command denied to user ‘test0525‘@‘10.189.80.60‘ for table ‘adm_cnyloan_rate‘

一、背景

程序通过以下方式获取表的主键信息

Connection.getMetaData().getPrimaryKeys(String catalog, String schema, String table)

select command denied to user ‘test0525‘@‘10.189.80.60‘ for table ‘adm_cnyloan_rate‘_第1张图片

二、结论

出现这个提示肯定是当前mysql子账号无权限

三、排查

执行以下命令查看当前数据库拥有哪些数据库权限

SHOW GRANTS FOR dataBaseName

select command denied to user ‘test0525‘@‘10.189.80.60‘ for table ‘adm_cnyloan_rate‘_第2张图片

当前程序连接的就是regulation数据库,也能执行任何语句,但是界面的功能还是提示select command denied to user,这真tm日了狗了

 select command denied to user ‘test0525‘@‘10.189.80.60‘ for table ‘adm_cnyloan_rate‘_第3张图片

 经过debug发现 this.getDatabaseIterator(db)  方法获取了当前jdbc信息下所有数据库列表,在循环执行

SHOW KEYS FROM tableName FROM dataBase

在SQLyog执行结果和应用程序提示一样,确认无权限

1 queries executed, 0 success, 1 errors, 0 warnings

查询:SHOW KEYS FROM adm_cnyloan_rate FROM `crm`

错误代码: 1142
SELECT command denied to user 'test0525'@'10.80.88.17' for table 'adm_cnyloan_rate'

执行耗时   : 0 sec
传送时间   : 0 sec
总耗时      : 0.035 sec
 

四、解决方式 

一般高权限账户执行 

-- 查询权限

grant select on dataBase_name.* to user_name 

需要root解决 

-- 所有权限

grant all privileges on dataBase_name.* to user_name;

-- 刷新权限

flush privileges;

你可能感兴趣的:(mysql,数据库)