Retrieve client ip address in mysql

后端 未结 4 1893
悲&欢浪女
悲&欢浪女 2020-12-05 14:28

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          


        
相关标签:
4条回答
  • 2020-12-05 14:36

    @mvf - instead of reverse you could do:

    SELECT SUBSTRING_INDEX(USER(), '@', -1) AS ip;
    
    0 讨论(0)
  • 2020-12-05 14:40

    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.

    0 讨论(0)
  • 2020-12-05 14:40

    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();

    0 讨论(0)
  • 2020-12-05 14:55
    SELECT REVERSE(SUBSTRING_INDEX(REVERSE(USER()),'@',1)) as ip;
    SELECT SUBSTRING(USER(), LOCATE('@', USER())+1) as ip;
    
    0 讨论(0)
提交回复
热议问题