Show MySQL host via SQL Command
MysqlSqlDatabaseMysql 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';