Show MySQL host via SQL Command

后端 未结 4 570
再見小時候
再見小時候 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条回答
  •  -上瘾入骨i
    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.

提交回复
热议问题