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.
-
It's unlikely you have multiple IPs; what exactly have you tried, using what kind of client software, and what came back? – Pekka Apr 17 '16 at 16:35
-
127.0.0.1 or use `ifconfig -a` – Ed Heal Apr 17 '16 at 16:35
-
It's external so I can't use 127.0.0.1 – GapplesPvP Apr 17 '16 at 16:37
-
1Please edit your question to clarify. From what machine are you trying to connect to your MySQL server? What OS is running on your MySQL host machine? What OS is running on the machine from which you're trying to connect? Are the two machines on the same local area network? What happens when you try it? The machine name `localhost` is a DNS synonym for `127.0.0.1`. Does your machine have its own host name? If it does, try using it. If it doesn't you need to figure out its IP address. That's an operating-system-specific – O. Jones Apr 17 '16 at 16:53
-
I edited it explaining more – GapplesPvP Apr 17 '16 at 17:12
-
what is ip type static or dynamic?? – Altmish-E-Azam Apr 17 '16 at 17:35
-
A sensible configuration for MySQL has it listening *only* on a UNIX socket and not on any IP address. Look at your configuration file to see if you are listening on a network interface at all. – Quentin Jul 24 '18 at 22:17
5 Answers
Use status in mysql prompt
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.
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.
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.

- 14,264
- 6
- 62
- 62
Pretty old, but I ran into the same problem today and maybe it helps someone else. I find out how to use the MySQL syntax:
SHOW VARIABLES
Where, to filter your hostname, it would be:
SHOW VARIABLES WHERE Variable_name = 'hostname'

- 2,466
- 22
- 30
Better way is:
If you are using Debian/Ubuntu Linux one file is located at /etc/mysql/my.cnf location.
However, in my installation I see:
/etc/mysql/mariadb.conf.d/50-server.cnf
Just onpen this file: nano <path/to/this/file> search for: [mysqld]
user = mysql
...
.
.
.
bind-address = 127.0.0.1
bind-address is your local-host address. 127.0.0.1 is the IP address of local machine on which Mysql server is hosted. It can be something else like: 10.208.8.122, Its still is teh IP address of local machine but for remote conenction. So one can reach this Mysql server through this IP

- 496
- 4
- 7
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
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

- 698
- 6
- 18
-
-
I am connecting it through a website where it needs to connect to my database – GapplesPvP Apr 17 '16 at 17:22
-
-
check out this answer http://stackoverflow.com/questions/15873060/how-to-get-machine-name-from-ip-address-in-sql-server-2008 – 0xtvarun Apr 17 '16 at 17:27
First you have to find out your external IP to allow external web server to connect to your local MySQL server.
User one of these services:
- http://www.knowmyip.com/
- http://whatismyipaddress.com/es/mi-ip
- https://www.iplocation.net/find-ip-address
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)
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:
Check System firewall (windows firewall, Linux iptables or so one). And check possible 3rd party firewalls installed.
Allow your local MySQL server to accept external requests, some installation does not accept it "out-of-the-box". Access to My.cnf file and search the directive to allow external connections. It's well explained here: http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
Finally, you have to bind external permissions to user you will identify with. Here you will find a good explanation: How to allow remote connection 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.
Get lucky!