Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting ip address using MySQL query

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?

like image 490
Jesika Avatar asked Feb 14 '14 10:02

Jesika


People also ask

What is data type for IP address in MySQL?

MySQL. While MySQL doesn't have a data type for IP addresses, it's still easy to compare IPs in MySQL. Using inet_aton you can convert your IP addresses to integers before you compare.


1 Answers

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();
like image 62
Vignesh Kumar A Avatar answered Sep 18 '22 19:09

Vignesh Kumar A