How can I connect to a MySQL deamon on other host? - mysql

I'd like to connect to MySQL (deamon is running on my VPS) via HeidiSQL. I've created new user, commented bind-adress option and when I try to connect with it via HeidiSQL, I've got an error 2003: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10061).
What should I do?

It could be a number of factors.
See if a firewall is blocking your traffic to the other host
Can you simply ping the host from the client machine?
Can you also open a simple telnet session to the host on port 3306 ?
(If the telnet is accepted, you will probably see some characters appear and you will remain in the telnet session for a few seconds before the connection is closed. If not accepted, you will see the message Connection refused.)

There's a simple checklist for this:
Is your MySQL server bound to "localhost" only? It might be listening for connections only on 127.0.0.1 or ::1 instead of any which is usually 0.0.0.0. Try connecting on your server to your server with mysql --host=host_ip where host_ip is your network IP address. I think the default is localhost-only.
Is port 3306 firewalled? Many distributions allow only SSH by default, so you may need to open this up to your client machine. Try not to open this up to everyone on the internet as having an open MySQL port is asking for trouble. It's always best to limit access to a set of specific IPs if possible.
Can you connect via an SSH tunnel instead? This is far more secure as it means your 3306 port is properly firewalled. There are many tools for creating SSH tunnels, but the basic principle is to forward a local port of your choosing to the remote server's port 3306.

Related

Can't connect remotely to MySQL cPanel database

I can't connect remotely from Nodejs to a MySQL database from a domain. I've searched a lot, my ip is listed in the host list, and I've also checked the MySQL variables and the bind-address is set to *.
And, also, does anyone know why when I try to add a new host for remote mysql connections it says that the % wildcard is not allowed?
With another domain it works just fine.
Please help me figure it out.
Thanks!
You need to check if the port is open from remote by using MySQL workbench or other clients. You can also use telnet in the command line:
telnet {database ip} 3306
If you got a timeout, It seems there is a Firewall or Mysql config not listening remote IPs so call your ISP or hosting provider and ask them for open access.
But if you got "access denied" message or telnet connection was successful, we have something wrong in MySQL user privilege.

Can`t connect to mysql server on X.X.X.X on Windows

As the title says I want to connect remotely to mysql and it is on windows server but I got this error message.
Cant connect to mysql server on X.X.X.X
I am tring it with HeidiSql
I have MariaDB installed.
Also I can connect to server using remote connection.
Server is running and can connect to mysql localy
What have I tried:
I located my my.ini file and checked that I dont have one of these commands:
Skip-networking
bind-address = some IP
I didnt have them there in the first place
I logged in my MariaDB terminal and granted all permisions to user using this:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.100.%'
IDENTIFIED BY 'my-new-password' WITH GRANT OPTION;
I have added port 3306 to windows firewall
I guess it is worth mentioning that I cant ping that server either
if I do
ping X.X.X.X
it returns:
Pinging X.X.X.X with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for X.X.X.X:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
I have spent many hours on forums and tried all instructions but still cant connect.
Any help would be much appreciated!
The detailed problem can be from two different causes:
First option:
MySQL is binded to 127.0.0.1 or no ip at all. Check netstat on windows cmd for locating 3306 port opened to mysql process and binded to your network LAN interface or 0.0.0.0 (not to loopback / 127.0.0.1 // ::1)
For check netstat, use netstat -a -n -o, you can see in the response the PID of the process too.
For check MySQL is working on the same machine, try to connect from local console using mysql -h 127.0.0.1 (for localhost connection) or mysql -h (your LAN IP) (If you have mysql binded only to your LAN IP address).
Second option:
If first test are OK. Maybe windows firewall is not configured correctly. Try to disable windows firewall (double check disabling it). The error response on your question are because windows firewall are active and blocking connections. When you have verified you can reach 3306 with firewall off, enable it and configure. Check always you're opening the port on the required network profile (Remember, windows firewall can have different rules for private / public connections).
For check firewall correctly configured, try to access to the 3306 port on the computer from another comp on the LAN.
If you have a huge LAN network with VLANs and similar technologies, check your routing topology. Also, remember always for initial checks, disable windows firewall. Your ping are failing because firewall are enabled.

Why is my MySQL IP address different than physical server IP it is running?

This may be hugely a dumb question, but I*m a novice to MySQL, and I just discovered that MySQL has different ip i.e. 127.0.0.1 and its hostname (localhost) than the machine ip which is 192.168.1.3 and machine hostname is ceres, why is it so ?
I connected to MySQL running on different machine using MySQL workbench :
and it shows it logged me to mysql root user to 127.0.0.1 on pi#192.168.1.3
then
I wanted to insert data to db remotely using arduino MCU and i can definitely not write 127.0.0.1
Every server is IP 127.0.0.1 to itself. If you want to connect to MySQL installed in a machine where you are logged in, you will use IP 127.0.0.1 or localhost but if you want to connect to MySQL on that machine via another machine, you will have to identify its IP so that you can connect via this IP. That's why remotely you will connect to your MySQL server via IP 192.168.1.3 and not on 127.0.0.1. localhost is still IP 127.0.0.1
127.0.0.1 is the loopback interface, and is used when you try to connect to the mysql service locally (on the same server where the mysql service is running).
If you need to connect to the mysql service from another machine, you will need its IP address for it. You can use ifconfig to see what IP address is assigned to the server.
You need to understand a bit about TCP/IP to follow what is going on here. Every TCP/IP stack (implementation) has the internal loopback interface under the address 127.0.0.1 (for IPv4) or ::1 (for IPv6). This makes it easy to access the stack on the local machine without knowning it's TCP/IP address (or even if it has got none).
Then each machine participating in a TCP/IP network needs an address under which it is known in this network (in your case 192.168.1.3). When you work on your local machine then it doesn't matter if you use it's public IP address or it's loopback interface. A third option is the name localhost which resolves to the loopback interface. But watch out: it depends on the OS if that ends up at the IPv4 or the IPv6 variant.
As you know you can specify a host for a user, which decides from which it can connect. And here user#localhost and user#127.0.0.1 (or user#::1) are not the same host. The MySQL terminal implicitly treats localhost and loopback IP address as the same, for the user's convenience, but other clients do not. The bind address mentioned here is usually not involved at all. This is for special scenarios not relevant here. In over 10 years I never had to set a bind address for MySQL.
Update: I hope that downvoters comment on their action to show if something needs to be improved in my answer or they are just ignorant.

How to connect to MySQL Workbench?

I've bought a server from CloudAtCost.com and all the information it gives me about my server is Server ID, IP Address, Netmask, and Gateway. I can SSH in just fine, but I can't get MySQL Workbench to connect to it. I've tried both Standard (TCP/IP) and Standard TCP/IP Over SSH.
I figured it out. I was using "user" as my username when I needed to use "root".
MySQL server needs to be running.
Network connections need to be enabled.
You need to know what port MySQL is running on (default is 3306).
If reverse DNS lookup has not been disabled, MySQL has to be able to resolve IP address to hostname.
MySQL User has to be created and assigned a password, a username and host, host is either the specific host connecting or (less secure) a '%' wildcard for host. If DNS lookups are disabled, host will be an IP address.
Connections to the MySQL port (by default it's 3306) may be "blocked" by firewall...
There are a lot of possible reasons.
When we can't connect, there's usually a MySQL error message that indicates the kind of problem encountered.
But, my preference would be to only allow IP connections from 127.0.0.1. (We always turn off reverse dns lookups on our MySQL servers.)
I'd use ssh port forwarding (tunneling). Choose a port to use on your local machine, e.g. 13306, and configure SSH to "forward" connections to that port through the ssh connection...
You can configure that in the .ssh/config for the specific remote server, e.g.
Host remoteserver
LocalForward 13306 localhost:3306
You'd need to first ssh to the remoteserver, and keep that session open.
Then on your local machine, MySQL Workbench would connect to localhost port 13306. On the MySQL server side, that will be seen as coming from IP address 127.0.0.1,
Obviously, you'd need to have a user created, e.g.
GRANT USAGE ON *.* TO myusername#'127.0.0.1' IDENTIFIED BY 'mypassword'
And grant appropriate privileges.
Go to Mysql Workbench>Server Status>Note down the port number
and give hostname as localhost:your port number,usually its 3306

connect and fetch remote MySQL server from Mac

I ma following this tutorial on how to connect to a remote MySQL server, however It seems the command doesn't work and often results in Operation timed out when trying to connect to the server:
ssh mysql.xxxxx.com
I can connect directly from my hosting account but not through the Shell on my Mac OS.
There may be a firewall or other network security device in place that prevents you from being able to connect from your Mac. Also, it is possible that the MySQL server is not configured to allow inbound network connections.
You might ask your hosting provider if they filter access to the MySQL port (default is 3306), or if your host is pre-configured with a firewall, and you might check your MySQL configuration file to ensure it is listening for inbound connections.
When you ssh into a remote server, and you do not specify a user name, ssh defaults to your current user.
bobs-macbook-pro:~ bob$ ssh server.acme.com
is the same as:
bobs-macbook-pro:~ bob$ ssh bob#server.acme.com
Try using your username when 'sshing' into the remote mysql machine.
There are two ways to specify your username, either one should work.
1. bobs-macbook-pro:~ bob$ ssh bob#server.acme.com
2. bobs-macbook-pro:~ bob$ ssh server.acme.com -l bob