Reputation: 51
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.
Upvotes: 5
Views: 74542
Reputation: 2521
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'
Upvotes: 4
Reputation: 586
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
Upvotes: 2
Reputation: 15713
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.
Upvotes: 7
Reputation: 4527
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:
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!
Upvotes: 0
Reputation: 698
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
Upvotes: 1