c++ - MySQL触发器错误#2013-查询期间与MySQL服务器的连接断开

标签 c++ mysql triggers

我想创建一个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/

相关文章:

c++ - Eclipse for C++ - 调试器不会在断点处停止

c++ - 在 C++ 中生成代码模型的最简单方法是什么?

mysql - 协助选择

mysql - 我想根据 where 子句在不同列上显示一列数据总和

MySQL 触发器检查具有可能的 NULL 值的现有行

ios - Parse Cloud Code 触发器是否需要响应

sql - 模式中所有表的 PL/PGSQL 动态触发器

c++ - 通用工厂设计模式的实现

C++ safe boolean idiom 不能用 Visual C++ 10(2010) 编译

mysql - 这种数据库设计是否可以接受,或者有更好的方法吗?