Show MySQL host via SQL Command

后端 未结 4 569
再見小時候
再見小時候 2020-12-04 15:22
Show Database
Use database
show tables
Describe 

All good and well, but is it possible to show the current connections host. Not conne

相关标签:
4条回答
  • 2020-12-04 15:31

    Maybe

    mysql> show processlist;
    
    0 讨论(0)
  • 2020-12-04 15:34

    To get current host name :-

    select @@hostname;
    show variables where Variable_name like '%host%';
    

    To get hosts for all incoming requests :-

    select host from information_schema.processlist;
    

    Based on your last comment,
    I don't think you can resolve IP for the hostname using pure mysql function,
    as it require a network lookup, which could be taking long time.

    However, mysql document mention this :-

    resolveip google.com.sg
    

    docs :- http://dev.mysql.com/doc/refman/5.0/en/resolveip.html

    0 讨论(0)
  • 2020-12-04 15:35

    I think you try to get the remote host of the conneting user...

    You can get a String like 'myuser@localhost' from the command:

    SELECT USER()
    

    You can split this result on the '@' sign, to get the parts:

    -- delivers the "remote_host" e.g. "localhost" 
    SELECT SUBSTRING_INDEX(USER(), '@', -1) 
    
    -- delivers the user-name e.g. "myuser"
    SELECT SUBSTRING_INDEX(USER(), '@', 1)
    

    if you are conneting via ip address you will get the ipadress instead of the hostname.

    0 讨论(0)
  • 2020-12-04 15:43
    show variables where Variable_name='hostname'; 
    

    That could help you !!

    0 讨论(0)
提交回复
热议问题