I am new to google cloud but was just able to deploy the test Django app that google provided in their documentation. This process included downloading the cloud_sql_proxy and running the following in the terminal (MacOS):
./cloud_sql_proxy -instances="my-instance-274702:us-central1:fms"=tcp:3306
This command starts running the proxy in order to connect locally to the DB in the cloud. Everything was working fine until I terminated the proxy with ctrl + C. When I ran the following command to start the proxy again I got the following error:
ludovico#Ludovicos-MacBook-Pro django % ./cloud_sql_proxy -instances="my-instance-274702:us-central1:fms"=tcp:3306
2020/04/18 23:38:10 Rlimits for file descriptors set to {&{8500 9223372036854775807}}
2020/04/18 23:38:12 listen tcp 127.0.0.1:3306: bind: address already in use
I got this error the first time I did this but I fixed it by shutting down the MySQL server that was running on port 3306. Now however, port 3306 is already bound to the cloud_sql_proxy and so it is throwing an error and is unable to start the proxy. If I run the same command with port 3307 it works just fine:
./cloud_sql_proxy -instances="my-instance-274702:us-central1:fms"=tcp:3307
But Django does not look for port 3307 it looks for port 3306.
Is it possible to unbind port 3306? Better yet, is there a command to start running the proxy instead of binding and unbinding port 3306 each time?
use
ss -lptn
the sport command to show which port is bind to which process.
Then kill the process running on 3306 by
kill -9 {process_id}
this will unbind your busy port 3306. Then you can run process on 3306.
Related
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.
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
I have a Mac running Mavericks with MySQL installed from homebrew. When I try nmap localhost and I see:
3306/tcp open mysql
When I try this same command with my computer name:
nmap my_comp_name
I do not get 3306 but I get:
PORT STATE SERVICE
80/tcp open http
3128/tcp open squid-http
8080/tcp open http-proxy
It also says my computer name resolves to some ip address. When I try nmap with that ip address, I get the same response as above. I want to be able to connect to this database with Visual Studio running on my Parallels VM.
This happened some time yesterday and I finally figured out that Norton anti virus was installed blocking that port. So I uninstalled Norton with one of their scripts and restarted. Everything was working fine at work, and then I came home and again, the port is closed.
I do not have a firewall on for either my Mac or Windows (Parallels VM) machine. I cannot figure out why this port gets closed. I do not have a firewall set up on my home network either. This port has been opened in the past on my home network as well. I am at a loss of figuring out what is causing this port to just suddenly close without even rebooting my computer. I basically come home, and port 3306 is now closed. Any thoughts?
Edit: I have also tried adding port = 3306 in the my.cnf file, restarted apache, and that also does not solve my problem.
When you run nmap against localhost it uses IP address 127.0.0.1. When you run it against your hostname, it uses the 'real' IP address of your host.
Clearly you have MySQL configured to bind only on IP address 127.0.0.1, and need to change the config to bind to all addresses if you want to access MySQL from a different host (even if the host is running in a VM inside your machine).
Find the file /etc/my.cnf and see if it contains a line like
bind-address=127.0.0.1
If it does, remove it or change it to
bind-address=0.0.0.0
If my.cnf does not contain a line binding to 127.0.0.1, then you may have to find the script that starts MySQL and examine it to see how it sets the bind address.
You don't need to create or edit my.cnf
Open mysql launch file
vi ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
And change this line
<string>--bind-address=127.0.0.1</string>
to
<string>--bind-address=0.0.0.0</string>
And finally reload MySQL
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
This seems like a binding problem. It seems like it is binding to your private ip instead of all or 127.0.0.1/localhost. But that is just from the top of my head.
From the mysql documentation:
The MySQL server listens on a single network socket for TCP/IP
connections. This socket is bound to a single address, but it is
possible for an address to map onto multiple network interfaces. The
default address is 0.0.0.0. To specify an address explicitly, use the
--bind-address=addr option at server startup, where addr is an IPv4 address or a host name. If addr is a host name, the server resolves
the name to an IPv4 address and binds to that address. The server
treats different types of addresses as follows:
If the address is 0.0.0.0, the server accepts TCP/IP connections on
all server host IPv4 interfaces. If the address is a "regular" IPv4
address (such as 127.0.0.1), the server accepts TCP/IP connections
only for that particular IPv4 address.
Configuration
You can set bind-address directive in my.cnf. Edit /etc/my.cnf or /usr/local/etc/my.cnf, run:
$ nano /etc/my.cnf
Set the address to 0.0.0.0:
bind-address = 0.0.0.0
Make sure you delete the following line or comment out the following line:
#skip-networking
Save and close the file.
Finally restart the mysql service.
source.
I got the package postgresql-8.4.9.tar.bz2 on the postgresql website and installed it following the instructions on the file INSTALL. But when we try to run it, it doesn't work and throws this error:
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
I don't know, maybe it's because of some conflict with mysql. Does anybody know what's going on?
Thanks in advance!
It appears that another process is listening on port 5432. Try running the following command:
sudo netstat -tulpn | grep 5432
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.