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

Getting ip address using MySQL query

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

In MySQL query:

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

The result of ^ this query is: localhost.

SELECT @@hostname;

The result of ^ this query is: localhost.

But I need to get ipaddress like 192.168.1.2.

Question: How to get this result using mysql query?

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

To get the IP address only without the port number.

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