How to get the IP address [MYSQL]

2019-06-01 03:12发布

How can I get the IP address of mysql server running in the localhost machine?

The following query returns 'localhost' because of name resolution.

   Select SUBSTRING_INDEX(host,':',1) as 'ip' 
   From information_schema.processlist 
   WHERE ID=connection_id();

So what needs to be done to not take the name resolution into consideration or is there any other way of getting the IP address?

Thanks

1条回答
贪生不怕死
2楼-- · 2019-06-01 03:51

As for my knowledge you can't directly fetch the ip address of your localhost. But mysql has utitlity which is present in directory mysql\bin whose execution file name is resolveip for that you can execute it like this.

resolveip localhost

In command prompt please give this by pointing your command prompt path to bin directory. For further detail about resolveip click me!!!

It will return text output as like this

IP address of localhost is 127.0.0.1

This function is two way return i.e. Instead of resolved name if you give ip address like this

resolveip 127.0.0.1

It will return text output as like this

Host name of 127.0.0.1 is mypc.local, localhost

查看更多
登录 后发表回答