Show MySQL host via SQL Command

MysqlSqlDatabase

Mysql Problem Overview


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.

Mysql Solutions


Solution 1 - Mysql

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

Solution 2 - Mysql

Maybe

mysql> show processlist;

Solution 3 - Mysql

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.

Solution 4 - Mysql

show variables where Variable_name='hostname'; 

That could help you !!

Solution 5 - Mysql

This can also be achieved by one single command. I tried these queries in MySQL

to get hostname :

mysql> SHOW GLOBAL VARIABLES LIKE 'HOSTNAME';

to get port :

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCraig StewartView Question on Stackoverflow
Solution 1 - MysqlajrealView Answer on Stackoverflow
Solution 2 - MysqlAdrian CornishView Answer on Stackoverflow
Solution 3 - MysqlRadon8472View Answer on Stackoverflow
Solution 4 - MysqlGowtham VakaniView Answer on Stackoverflow
Solution 5 - MysqlVikas BansalView Answer on Stackoverflow