本文介绍了在MySQL中检索客户端IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用简单的SQL语句获取客户端的IP地址.我不想使用PHP或其他技术.仅纯SQL.当我使用
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();
我知道
dbouser@host.i.do.not.care.of
当我使用
SELECT CURRENT_USER();
我知道
dbouser@%
但是我如何获得普通IP?提前谢谢.
But how do I get the plain IP? Thanks a lot in advance.
推荐答案
您将仅获得与MySQL通信的客户端进程的IP地址.假设这就是您想要的:
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();
将为您提供在当前连接上连接到mysql服务器的主机名(如果未启用名称解析,则为IP地址,通常不会).
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.
这篇关于在MySQL中检索客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!