Warm tip: This article is reproduced from serverfault.com, please click

sql-使用MySQL查询获取IP地址

(sql - Getting ip address using MySQL query)

发布于 2014-02-14 10:45:24

在MySQL查询中:

SELECT host
FROM information_schema.processlist
WHERE ID = connection_id( )
LIMIT 0 , 30

此查询的结果为:localhost

SELECT @@hostname;

此查询的结果为:localhost

但是我需要像这样的ipaddress 192.168.1.2

问题: 如何使用mysql查询获得此结果?

Questioner
Jesika
Viewed
0
Vignesh Kumar A 2014-02-14 19:14:08

仅获取IP地址而没有端口号。

 Select SUBSTRING_INDEX(host,':',1) as 'ip' 
 From information_schema.processlist 
 WHERE ID=connection_id();