程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL用戶權限導致的創建Trigger失敗

MySQL用戶權限導致的創建Trigger失敗

編輯:MySQL綜合教程

說來慚愧,MySQL一直處於只會用,不怎麼理解的階段。甚至是一些較為深層次的管理,都不怎麼熟悉,得加強啊!

近日,系統測試,使用MySQL數據庫,需要在某個表上創建觸發器,數據庫是在本機安裝。但是,無論如何都無法創建觸發器,後台錯誤信息如下:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: TRIGGER command denied to user 'root'@'mortimer-PC' for table 't_user'
	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:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:841)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
	at com.apusic.jdbc.adapter.StatementHandle.execute(Unknown Source)
	at com.apusic.esb.base.util.SQLUtil.createDBObjectIfNecessary(SQLUtil.java:263)
	at com.apusic.esb.base.util.SQLUtil.createDBObjectIfNecessary(SQLUtil.java:225)
	at com.apusic.esb.config.trigger.mysql.MySqlTriggerManager.createTriggersIfNecessary(MySqlTriggerManager.java:83)
	at com.apusic.esb.config.trigger.TriggerConfigManager.deploy(TriggerConfigManager.java:331)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.apusic.esb.base.communication.CommInvokeUtil.invoke(CommInvokeUtil.java:139)
	at com.apusic.esb.base.communication.CommInvokeUtil.invoke(CommInvokeUtil.java:43)
	at com.apusic.esb.base.communication.CommInvokeUtil.invoke(CommInvokeUtil.java:27)
	at com.apusic.esb.base.communication.socket.server.CommSocketServer$RequestProcessor.run(CommSocketServer.java:99)
	at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)
2014-06-25 10:38:42 錯誤 [apusic.com.apusic.esb.config.trigger.TriggerConfigManager] 
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: TRIGGER command denied to user 'root'@'mortimer-PC' for table 't_user'
	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:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:841)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
	at com.apusic.jdbc.adapter.StatementHandle.execute(Unknown Source)
	at com.apusic.esb.base.util.SQLUtil.createDBObjectIfNecessary(SQLUtil.java:263)
	at com.apusic.esb.base.util.SQLUtil.createDBObjectIfNecessary(SQLUtil.java:225)
	at com.apusic.esb.config.trigger.mysql.MySqlTriggerManager.createTriggersIfNecessary(MySqlTriggerManager.java:83)
	at com.apusic.esb.config.trigger.TriggerConfigManager.deploy(TriggerConfigManager.java:331)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.apusic.esb.base.communication.CommInvokeUtil.invoke(CommInvokeUtil.java:139)
	at com.apusic.esb.base.communication.CommInvokeUtil.invoke(CommInvokeUtil.java:43)
	at com.apusic.esb.base.communication.CommInvokeUtil.invoke(CommInvokeUtil.java:27)
	at com.apusic.esb.base.communication.socket.server.CommSocketServer$RequestProcessor.run(CommSocketServer.java:99)
	at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)
分析錯誤信息:TRIGGER command denied to user 'root'@'mortimer-PC' for table 't_user',看起來是不允許root用戶在t_user表上執行TRIGGER命令,為啥不允許?

其次,分析錯誤信息本身,不允許執行神馬命令,看起來貌似是權限問題,Navicat連接數據庫,查看用戶權限,發現用戶“root@%”的“Trigger”一欄未選中!而此次連接的用戶,看起來是“root@mortimer-PC”,因此,“root@localhost”的規則,貌似不會生效,估計是此原因,造成無法創建觸發器。

調整“root@%”用戶的權限,選中“Trigger”欄,重啟MySQL服務,重新連接MySQL,創建觸發器,OK!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved