通过 SQL 命令显示 MySQL 主机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8283248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:49:51  来源:igfitidea点击:

Show MySQL host via SQL Command

mysqlsqldatabase

提问by Craig Stewart

Show Database
Use database
show tables
Describe <table>

All good and well, but is it possible to show the current connections host. Not connection_id, but the IP Address or Name of the host.

一切都很好,但是否可以显示当前连接主机。不是 connection_id,而是主机的 IP 地址或名称。

回答by ajreal

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.

根据您的最后一条评论,
我认为您无法使用纯 mysql 函数解析主机名的 IP,
因为它需要网络查找,这可能需要很长时间。

However, mysql document mention this :-

但是,mysql 文档提到了这一点:-

resolveip google.com.sg

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

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

回答by Adrian Cornish

Maybe

也许

mysql> show processlist;

回答by Radon8472

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

我认为您尝试获取连接用户的远程主机...

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

您可以从命令中获取像 'myuser@localhost' 这样的字符串:

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.

如果您通过 ip 地址连接,您将获得 ipadress 而不是主机名。

回答by Gowtham Vakani

show variables where Variable_name='hostname'; 

That could help you !!

那可以帮到你!!