今天遇到一个问题,在测试环境第一次跑elastic job的定时任务,因为要监控elastic job的日志,在程序运行中自动创建elastic job相关的表和索引(elastic job框架自带), 报一个没有建索引的权限异常:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: INDEX command denied to user 'root'@'10.1.0.85' for table 'job_status_trace_log'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:498)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbStorage.createTaskIdAndStateIndex(JobEventRdbStorage.java:147)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbStorage.createTaskIdIndexIfNeeded(JobEventRdbStorage.java:101)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbStorage.createJobStatusTraceTableAndIndexIfNeeded(JobEventRdbStorage.java:88)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbStorage.initTablesAndIndexes(JobEventRdbStorage.java:67)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbStorage.(JobEventRdbStorage.java:61)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbListener.(JobEventRdbListener.java:37)
at com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration.createJobEventListener(JobEventRdbConfiguration.java:46)
... 34 common frames omitted
数据库的配置如下:
spring.datasource.elasticjob.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.elasticjob.url=jdbc:mysql://10.1.1.176:3306/elastic_job_log?useUnicode=true&characterEncoding=utf-8&autoReconnect=true
spring.datasource.elasticjob.username=root
spring.datasource.elasticjob.password=park
spring.datasource.elasticjob.driver-class-name=com.mysql.jdbc.Driver
注意到测试环境的数据库是10.1.1.176,而异常信息中的ip却是10.1.0.85。10.1.0.85这个是我本机的ip地址。所以猜测是从我本机连过去到测试环境DB的用户root,没有权限。去到10.1.1.176查看root的权限:
SELECT USER ,HOST FROM mysql.user ;
返回结果如下:
user host
bg_user %
dba_user %
rep_user %
root %
sst %
test_user %
wenwei %
zx_root %
mpm 127.0.0.1
root 127.0.0.1
root ::1
root db01
debian-sys-maint localhost
root localhost
xtrabk localhost
再查看root的权限:
SHOW GRANTS FOR root@'%' ;
返回结果:
Grants for root@%
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*7CFF8AC89B5953B1033DD5FC8A86BB387B09CF75'
GRANT CREATE ON `park`.* TO 'root'@'%'
注意看返回结果,第二行没有返回INDEX 权限。
叫DBA帮忙加上权限,问题解决。