在MySQL查询中:
SELECT host
FROM information_schema.processlist
WHERE ID = connection_id( )
LIMIT 0 , 30这个查询的结果是:localhost。
SELECT @@hostname;这个查询的结果是:localhost。
但是我需要像192.168.1.2这样的I地址。
问题:如何使用查询获得这个结果?
发布于 2014-02-14 11:14:08
只获取没有端口号的IP地址。
Select SUBSTRING_INDEX(host,':',1) as 'ip'
From information_schema.processlist
WHERE ID=connection_id();发布于 2014-02-14 10:58:15
查询
select host from information_schema.processlist WHERE ID=connection_id();
如果不启用名称解析,.You将获得IP地址(如192.168.1.2.),而通常不启用该地址。
发布于 2020-12-16 08:26:05
在这个post的帮助下,您可以像这样重写它,这是一个很好的拆分函数:
Select user,CONCAT(Split_fn(host, "-", 2),'.',Split_fn(host, "-", 3),'.',Split_fn(host, "-", 4),'.',Split_fn(Split_fn(host, "-", 5),".",1)) as Ip_Address from information_schema.PROCESSLIST where ID = CONNECTION_ID()https://stackoverflow.com/questions/21777200
复制相似问题