从 mysql 查询中获取当前会话/进程 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2627058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get current session /process id from inside a mysql query
提问by Indra Ginanjar
I'm trying to create a table for pseudo array variable. That looks like
我正在尝试为伪数组变量创建一个表。那看起来像
CREATE TABLE IF NOT EXISTS `MyArray`.`ArrayTable` (
`ID` INT UNSIGNED NOT NULL COMMENT 'Hash value of SessionID + ArrayName' ,
`SessionID` INT UNSIGNED NOT NULL ,
`ArrayName` CHAR(26) NOT NULL
COMMENT '32 digit char - 6 digit longest process id (assumtion)' ,
`Index` INT UNSIGNED NOT NULL ,
`Value` TEXT NOT NULL ,
PRIMARY KEY (`ID`, `SessionID`) )
ENGINE = MyISAM;
The table is not normalized yet, 'hope this will make it a little simpler to understand :)
该表尚未规范化,'希望这能让它更容易理解:)
To avoid collission between client, there should be a differentiator between client session. For that reason i think need to know current session/process id (just like "SHOW PROCESSLIST") but really need to know IN WHICH process the query are?
为了避免客户端之间的冲突,客户端会话之间应该有一个区别。出于这个原因,我认为需要知道当前的会话/进程 ID(就像“显示进程列表”一样)但真的需要知道查询在哪个进程中?
回答by newtover
You can use connection_id()function.
您可以使用connection_id()函数。