我想创建一个MySQL触发器,当将一行插入MySQL表时,在其中执行C++程序。为此,我使用的是LIB_MYSQLUDF_SYS,它已成功安装为UDF。我的代码基于this教程。
这是我的触发代码:
DELIMITER @@
CREATE TRIGGER startSimulator
BEFORE INSERT ON `trigger`
FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd=CONCAT('/home/lab/Dropbox/simulator/version_unified/./simulator');
SET result = sys_exec(cmd);
END;
@@
DELIMITER ;
如果不清楚,则使用
./simulator
执行系统程序。但是,当我使用INSERT INTO trigger (trigger) VALUES (yes)
将行插入到“触发器”表中时,出现以下错误:#2013 - Lost connection to MySQL server during query
当我删除触发器时,查询执行正常。有谁知道为什么会这样吗?
mysqld --log-warnings=2
产生:130719 15:53:59 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
130719 15:53:59 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
130719 15:53:59 InnoDB: The InnoDB memory heap is disabled
130719 15:53:59 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130719 15:53:59 InnoDB: Compressed tables use zlib 1.2.3.4
130719 15:53:59 InnoDB: Initializing buffer pool, size = 128.0M
130719 15:53:59 InnoDB: Completed initialization of buffer pool
130719 15:53:59 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
最佳答案
更改
SET cmd=CONCAT('/home/lab/Dropbox/simulator/version_unified/./simulator');
至
SET cmd=CONCAT('/home/lab/Dropbox/simulator/version_unified/simulator');
当文件位于当前工作目录中时,将使用./。
关于c++ - MySQL触发器错误#2013-查询期间与MySQL服务器的连接断开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17733636/