Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to get with a simple SQL statement the IP address of the client. I do not want to use PHP or other techniques. Only pure SQL. When I use

SELECT USER();

I get

dbouser@host.i.do.not.care.of

When I use

SELECT CURRENT_USER();

I get

dbouser@%

But how do I get the plain IP? Thanks a lot in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
280 views
Welcome To Ask or Share your Answers For Others

1 Answer

You will only get the IP address of the client process communicating with MySQL. Assuming this is what you want:

select host from information_schema.processlist WHERE ID=connection_id();

Will give you the host name (or IP address if name resolution is not enabled, which it is usually not) connecting to the mysql server on the current connection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...