Not able to remotely access MySQL on GCP VM - mysql

I am having problem to connect to MariaDB on Linuc GCP VM. I have followed all practices to expose the VM on 3306, I use ephemeral IP. The VM is reachable as I have nginx installed. I have create remote user in MySQL, enabled remote access but still nothing. When i cannoct from my PC with MySQL Workbench i get connection error. What can it be?
I have also followed this:
enter link description here
Update
this the output of netstat:
$> netstat -ant | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Result of nmap is more intersting though:
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp closed https
3389/tcp closed ms-wbt-server
I do not see 3306 but it is a port I have opened on firewall rule in GCP... How can it be is not shown?

Ok, I have found a mistake. It was in the GCP firewall configuration rule. The tag name of the VM was spelled wrongly. thanks.

Related

MySQL port 3306 not accessible remotely. port enabled on Windows server firewall

It looks like weird happening, I've followed and fixed all the possible things but still MySQL port 3306 is not accessible remotely.
Here's my setup:
Machine: Windows Server 2012 R2
MySQL Server: 8.xx
Settings have been applied:
In my.ini bind-address did to 0.0.0.0 and and thus after exec command netstat -an this is what I get TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
From Windows Firewall I've enabled port 3306 inbound/outbound both. and set that to allow edge traversal as well
From the MySQL server I've created a user with % all host and then provided permission to all databases as well. which has been checked
I guess these are the actions I took afterward. But this is not working at all.
When I'm trying to do telnet server_ip 3306 error: Connecting To server_ip ...Could not open a connection to the host, on port 3306: Connect failed from other machines. The local host is working fine.
I don't see any other workaround that could else cause this issue?
I've tried installing MySQL 8.0 on my local PC:
With default setting
Firewall turned on
No firewall exception added manually
Then I tried to connect from a remote Windows Server 2016 Standard using telnet local_ip port through command-prompt and I received this:
J
8.0.27
ZPhqTaMC v|)64Pthmmysql_native_password
Which means the connection has been established. I test it further using SQLYog tool:
and for sure I can connect to it.
What I did next was I went to my firewall setting here
Control Panel\All Control Panel Items\Windows Defender Firewall\Allowed applications
and removed all related firewall exception that was made during the installation so I've removed the following:
mysqld
port3366 <-- this is the port I used
port33060
And when I tried to connect remotely, it tells me this:
Connecting To local_ip...
Could not open connection to the host, on port 3366: Connect failed
This confirms my suspicion that firewall have blocked the connection. Now, OP said that the port have been added to the firewall but still can't connect so my first step after that is adding back mysqld into the firewall exception.
In the firewall setting click "Allow another app"
The "Add and app" dialog opens then click "Browse"
Locate mysqld from MySQL folder - usually found in C:\Program Files\MySQL\MySQL Server 8.0\bin
Click "Add" then tick both "Public" and "Private" checkbox
Once I've done that, I tried connecting and it's successful. Note that I did not re-add the ports that I've removed previously but I still can connect remotely. Also, I didn't add bind-address in my.ini setting.

can I connect to MySQL on a GCP CE VM instance from Windows MySQL Workbench?

As the title implies, I'm looking to connect from my windows laptop, to a GCP VM instance, in which mysql is running there. The database works fine, and if I go into an ssh client from their cloud connection, I can directly use mysql client and interrogate the DB.
I would like to use my local windows MySQL Workbench app, and be able to perform queries, just like I did in my localhost version I built before porting it up to GCP.
How to do this, (without subscribing to GCP Cloud SQL) and attach to my VM instance's sql?
///////////////////////////////////////////////
from John's comment, here's my net stat output:
netstat -tlnp | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 17007/mysqld
and the 3306 is indeed in the port list in mysql:
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.01 sec)
so my conclusion is that I need to open the port?
#john:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1669/mysqld
NAME NETWORK DIRECTION PRIORITY ALLOW DENY DISABLED
mysqlaccess default INGRESS 1000 tcp:3306 False
Telnet test of the port from my laptop:
C:\Users\fumanchu>telnet x.x.x.x 3306
[ 5.7.33-0ubuntu0.16.04.1zzzzzzzz}<[:X'mysql_native_password
Connection to host lost.
attempt to use GUI from MySQL Workbench:
ADDED console GCP log showing my VPC entry is there:
mysqlaccess
Ingress
Apply to all
IP ranges: 0.0.0.0/0
tcp:3306
Allow
1000
Off — —
if you can connect via ssh.
change the connection method
There you can enter the same data as in your previous ssh connction
Per #JohnHanley here is a summary of my issues and steps:
Get a working setup of mysql workbench with a local pc database. This ensures you have the DB, and the connection to a local machine working correctly.
export the database to a remote system, in my case it was GCE linux VM (ubuntu I used) There are many easy steps to follow on exporting the db (mysqldump based)
ensure linux vm has mysql server and client setup, and import the db
now to setup the ssh connection:
ensure the port 3306 is open on the linux vm, by going to the VPC service for your vm/project, and insuring the port is open, or adding a rule to expose port 3306 ingress.
connect to the vm (you should have already done this before step 3), by using the GCE console and connecting to the instance. This also ensures you have the local files on the pc for ssh created. (~/.ssh/google_compute_*)
connect to the VM from your pc. use gcloud console tools to check the next step. if you haven't been using gcloud console tools yet, get them installed open a command / powershell window.
type "gcloud compute ssh "name of instance". if this connects, you now know you have the server properly configured for ssh, and accept external requests.
then setting up mysql workbench is same setup of gcloud ssh request...it can use the same credentials and script, which the helper files exist in the above /.ssh/ folder I referenced.

I'm new to programming and I successfully installed XAMPP but when I run the Admin on MySQL, local host refuses to connect

This site can’t be reachedlocalhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
This is the message that popped up
Please check the port first. Is your port is listening correctly or there may be a firewall preventing you to connect to that port.
You can use the following command to check the open ports
sudo netstat -tulpn | grep LISTEN
To check the specific port use
sudo lsof -i:22 see a specific port such as 22

Database Not connectable through Public IP

NOTE. operation system is ubuntu 14.*
I am breaking my head over my connection on my MYSQL server. I try to connect to my MYSQL server internal through my public ip. But i am unable to connect. While i am able to connect when i connect to localhost and when i connect externally.
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
I commented the bind-adress out and this should bind the addres to 0.0.0.0. I also tried to setup the bind-adres to 0.0.0.0. This also doesnt work.
My hosts file is setup up as follows:
127.0.0.1 MY-IP
When i telnet on port 80 to my public ip there is no problem.
telnet MY-IP 80
I get:
Trying MY-IP...
Connected to MY-IP.
Escape character is '^]'.
But when i try this on port 3306 it keeps on:
Trying MY-IP...
I also granted all the right permissions to my MYSQL users. And i am possible to connect externaly and internaly. But it is not possible for me to connect internaly with my public ip.
Also i tried to find a solution with netstat.
netstat -tln
give mes
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
EDIT: Just disabled UFW. It still doesnt work.
ufw status
Status: inactive
EDIT2: Is it possible that mysql is ignoring the /etc/hosts file?
Could somebody help me a bit further with some great ideas where the problem might be.
You should change the bind address to 0.0.0.0 then restart the mysqld. Also make sure there is no firewall enabled:
iptables -n -L
if there are rules, blocking port 3306, delete them, or just disable the firwall with
iptables -F
also use netstat to check if the server is listening on the external ip:
netstat -tupan |grep :3306

how to add a port to mysql server

I want to add to MySql another tcp port that I can connect to that port from my application
I have a duplicate of my application and I'm running them both from the same machine. They both are connected to the MySql server that are running on the same machine. The problem is that the default port 3306 is already taken.
You cannot bind mysqld to listen to multiple ports. The only way you can achieve this is with internal routing rules which would forward the target port to 3306.
If you are on linux, you can achieve this using iptables. iptables is a bundle of fun normally reserved for system administrators though.
Is there a reason why both copies of your application can't connect to the same port 3306? Normally you should be able to have any number of clients connecting.
You can do that with something like this:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 9005 -j REDIRECT --to-port 9000
Where eth0 is your network dev, 9005 is your "source port", and 9000 the port where your service is running. Oh, that example is for TCP protocol only.
You can find more examples about port redirection
here. Useful site for Linux, btw.
A single mysql instance can host multiple databases. So an alternative for you is that each application connects to the same mysql instance running at port 3306, but each uses a different database name.