如何在本地主机上找到 MySQL ip?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36679189/
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:43:55  来源:igfitidea点击:

How to find MySQL ip on localhost?

mysql

提问by GapplesPvP

I am running my MySQL database on my machine, how do I get the ip of that MySQL server? I have already tried getting the ip of the machine but that doesn't work. I am running on Windows 8 OS on my machine and what I'm trying to do is connect a web page to my MySQL database which is on the MySQL server. They are not on the same network.

我在我的机器上运行我的 MySQL 数据库,我如何获得那个 MySQL 服务器的 ip?我已经尝试过获取机器的 ip 但这不起作用。我在我的机器上运行 Windows 8 操作系统,我想要做的是将网页连接到 MySQL 服务器上的 MySQL 数据库。他们不在同一个网络上。

回答by Amitesh

Use status in mysql prompt

在 mysql 提示中使用状态

mysql> status

OR

或者

 mysql> \s

Other ways,

其他方法,

SELECT SUBSTRING_INDEX(USER(), '@', -1) AS ip,  @@hostname as hostname, @@port as port, DATABASE() as current_database;

SELECT * FROM information_schema.GLOBAL_VARIABLES where VARIABLE_NAME like 'hostname';

SELECT host FROM information_schema.processlist WHERE ID=connection_id();

Will give you the host name (or IP address if name resolution is not enabled, which it is usually not) connecting to the mysql server on the current connection.

将为您提供连接到当前连接上的 mysql 服务器的主机名(如果未启用名称解析,则为 IP 地址,通常不会)。

The SQL query SHOW VARIABLES WHERE Variable_name = 'hostname'will show you the hostname of the MySQL server which you can easily resolve to its IP address.

SQL 查询SHOW VARIABLES WHERE Variable_name = 'hostname'将向您显示 MySQL 服务器的主机名,您可以轻松地将其解析为其 IP 地址。

SHOW VARIABLES WHERE Variable_name = 'port'

Will give you the port number.

会给你端口号。

You can find details about this in MySQL's manual: https://dev.mysql.com/doc/refman/8.0/en/show-variables.html.

您可以在 MySQL 手册中找到有关此内容的详细信息:https: //dev.mysql.com/doc/refman/8.0/en/show-variables.html

回答by Dimas Pante

Preety old, but I ran into the same problem today and maybe it helps someone else. I find out how to use the MySQL syntax:

太老了,但我今天遇到了同样的问题,也许它可以帮助其他人。我了解了如何使用 MySQL 语法:

SHOW VARIABLES

Where, to filter your hostname, it would be:

在哪里过滤您的主机名,它将是:

SHOW VARIABLES WHERE Variable_name = 'hostname'

回答by 0xtvarun

If you are connecting to the database from the machine where the SQL server is installed then you will be able to access it via localhost on port 3306

如果您从安装 SQL 服务器的机器连接到数据库,那么您将能够通过端口 3306 上的 localhost 访问它

If you are accessing it through a different machine, then connect to the IP address of the machine where the SQL serve is installed on port 3306

如果是通过不同的机器访问,则连接到安装SQL serve的机器的IP地址3306端口

回答by manuelbcd

First you have to find out your external IP to allow external web server to connect to your local MySQL server.

首先,您必须找出您的外部 IP 以允许外部 Web 服务器连接到您的本地 MySQL 服务器。

User one of these services:

使用以下服务之一:

After that, you need to allow this "outside" access. You will need your router admin access (web, SSH or directly by USB). Open desired port, by default 3306. Redirect it to your local machine ip (it usually is like 192.xx.xx.xx)

之后,您需要允许此“外部”访问。您将需要您的路由器管理员访问权限(Web、SSH 或直接通过 USB)。打开需要的端口,默认3306。重定向到你的本地机器ip(通常是192.xx.xx.xx)

Once you have configured your router to connect MySQL port to your internal-lan machine, you need to open this port in your machine. For that you will need to:

一旦您将路由器配置为将 MySQL 端口连接到您的内部局域网机器,您需要在您的机器中打开此端口。为此,您需要:

If everyting went OK then you will be able to serve MySQL service from your local machine, through your router to the external world.

如果一切顺利,那么您将能够从本地机器通过路由器向外部世界提供 MySQL 服务。

Get lucky!

幸运!