Unable to connect to mysql running inside WSL2 - mysql

I have the mysql server running inside WSL2, but I am unable to connect to it from MysqlWorkbench or Intellij Idea.
I tried the following command:
netsh interface portproxy add v4tov4 listenport=3306 listenaddress=0.0.0.0 connectport=3306 connectaddress=172.24.132.32
Which is supposed to forward a request to port 3306 to WSL2 IP. But still, it didn't work. Is there any way to solve this?
The following is the output of the netstat command:

It's easiest to use localhost, 127.0.0.1, or (if on IPv6) ::1 to access services running in WSL2 from Windows.
WSL includes a feature known as "localhost forwarding" which is enabled by default. This will (as it sounds) automatically forward traffic on the Windows localhost to the WSL2 instance, assuming that the port is listening in WSL2 (but not in Windows).
If this doesn't work, then you may have run into a WSL bug where localhostForwarding breaks when hibernating, or when Fast Startup is enabled in Windows (it is the default). If that's the case, try running the following in PowerShell:
wsl --shutdown
Then restart and try it again.
The IP address should work, but you don't mention how you are getting that IP. It changes every time WSL restarts, which is why it is generally preferred to use localhost. But if you want to try the IP, make sure that it is the one that you get from ip addr show eth0 inside WSL2.

Related

Cannot connect to MySQL installed on GCP Virtual Machine

I've installed MySQL on a Google Cloud Virtual Machine (debian buster). What I want to do is to make this accessible publicly (using username / password obviously).
As far as I can tell the server is visible from the outside world, as I can ping the IP and I get results, and I think I've set up a user correctly and given the appropriate permissions so I can log in.
For info, my firewall settings on GCP look like this (this is just the egress, there is one exactly the same for ingress):
Which I'm assuming is correct and leaves the correct port open?
The issue I have when I use MySQL Workbench is that when I try to create a new connection, it gives me the following error:
Your connection attempt failed for user 'username' to the MySQL server at [my ip address]:3306:
Unable to connect to localhost
Please:
1 Check that MySQL is running on address [my ip address]
2 Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the user username has rights to connect to [my ip address] from your address (MySQL rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for [my ip address] connecting from the host address you're connecting from**
Any pointers would be gratefully received.
Update: What is really confusing me is the 'Unable to connect to localhost' error. I'm not trying to connect to localhost...?
Update 2: As per comments, results of the following commands:
Note I am trying to connect using the matprichardson username. The svc2toria user is pointing to my own IP address.
Mat, If you want to use your Google Cloud Instance Database using your MySQL workbench. I suggest you connect to it through an SSH tunnel. So, this problem won't happen. I also ran into this problem several times. Connecting through SSH made the job done.
But if your need is something else, this would not help you at all. If your only purpose is managing your database from your local machine using the MySQL workbench. This will work nicely. Create a USER in your Debian VM. and open port 22 to the public. Also, make sure to have strong credentials or a better key file when connecting through SSH. This method is working for every cloud VM database. I'm using this method for G-Cloud, Azure, and AWS. After all of your work is done. Close port 22 (SSH).
My best guess will be because of number 2. "Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)".
Your Virtual Machine will have network security controls / firewall which will be blocking port 3306 by default.
I don't use Google cloud but I believe you are looking for "network details" -> "Firewall rules".
did you change your mysqld.cnf already?
bind-address = 0.0.0.0
As none of the suggestions posted worked I went for the rather more nuclear option of deleting and rebuilding my VM and setting MySQL up again from scratch. I must have done something wrong in my initial setup, as things worked without any issues at all once I’d done this.
The location of the MySQL configuration file differs depending on the distribution.
In Ubuntu and Debian the file is located at /etc/mysql/mysql.conf.d/mysqld.cnf
while in Red Hat based distributions such as CentOS, the file is located at /etc/my.cnf
Open the file with your text editor :
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for a line that begins with bind-address and set its value to the IP address on which a MySQL server should listen.
By default, the value is set to 127.0.0.1 (listens only in localhost).
In this example, we’ll set the MySQL server to listen on all IPv4 interfaces by changing the value to 0.0.0.0
bind-address = 0.0.0.0
# skip-networking
If there is a line containing skip-networking, delete it or comment it out by adding # at the beginning of the line.
In MySQL 8.0 and higher, the bind-address directive may not be present. In this case, add it under the [mysqld] section.
Once done, restart the MySQL service for changes to take effect. Only root or users with sudo privileges can restart services.
To restart the MySQL service on Debian or Ubuntu, type:
sudo systemctl restart mysql
On RedHat based distributions like CentOS to restart the service run:
sudo systemctl restart mysqld
For more Detail Read Here

How to Debug CUDA code on a remote server?

I want to debug the CUDA code on the remote server, My equipment is as follows:
Pc: Ubuntu 16.04,CUDA 8.0.61,nvcc v8.0.61,Geforce MX150 and integrated graphics
Server: Ubuntu 14.04,CUDA 8.0.61,nvcc v8.0.61,Tesla P100-PCIE*2
I have installed the Nsight Eclipse Edition 7.5 on my pc, What I want is to use the remote debug function that I can use the Visual debug window on my PC and remote gdbserver,But I have encountered some problems.
When I configure remote debugging to try to connect to a remote server,the Connection timed out return from the connection.
I don't know if it's related to the port. When I log in to the server, it looks like this:
SSH -P 50034 username#xxx.xxx.xxx.xxx
When setting up the connection, I noticed that port 2345 seems to be used, so I don't know if there is a conflict.The setting page is like this:
So far,I have tried the following:
Reinstall the Nsight Eclipse Edition,and debug sample code on the server in the command line which runs correctly.
Some forums mention that port 2345 should be opened,AFAIK,You can use this port as long as the port is not occupied when requested,but,I am not sure about it.
Considering that the server has certain restrictions on the visitor's IP address,so I tried to change the network several times but failed in the end.
Any ideas?
This problem was finally solved and I got a sigh of relief.
Since my server is in a cluster, ports are mapped. For example, the command when connecting to the server the port id should be attached with (i.e.ssh -p 50034 uesrname#xxx.xxx.xxx.xxx), so when the nsight eclipse edition's port 2345 (default) accesses the server, it does not recognize the port, then the time out delay is given, so I mapped the port 2345 to the server's port 2345, The map roughly as shown below:
-A PREROUTING -d xxx.xxx.xxx.xxx -p tcp -m tcp --dport 2345 -j DNAT --to-destination xxx.xxx.xxx.xxx:2345
The first xxx.xxx.xxx.xxx is the server's IP adress while the last one is the real adress of ur server in the cluster such as 11.11.11.24,which is Owing to the different conditions.

Couldn't connect linux mysql server from other server

I tried everything which I found on google but couldn't connect linux mysql server from other server, Server where Mysql is located is Linux OS and from where I want to connect that is ubuntu, What can I do?
I already grant all privileges to user, bind-ip-address, and comment localhost etc. Is there any sqlserver's internal configurations?
Did you check ssh connectivity between two servers? if it doesn't works configure sshd properly and if ssh connectivity works fine then,The Target server's internal firewall might be blocking remote mysql connections.
After a long R&D, when nothing help me, I think about port number, and that was silly mistake, actually I check available port on AWS for that instance from I want to connect and found I forgot to open 3306 (default MySQL port). I just add this and everything became perfect.

Why am I getting ECONNREFUSED connecting to localhost MySQL from docker node app?

I have a locally running MySQL server.. it's NOT within a container. My app is going to be hitting RDS so no sense in going that route. My app was able to hit RDS no problem, as a test. But obviously I want to hit something local for local development.
From my terminal I can do mysql --user=root --password=password mydb successfully.
And as I'm not getting a timeout error, from my container I can ping 127.0.0.1:3306 with no issue.
I also used console to see I am definitely passing the right info, after having updated the values from RDS to locally running MySQL.
Docker container has its own network IPs, including its own localhost. So you basically need to be sure of two things:
That your host MySQL is listening in all of its interfaces (bind-addres = 0.0.0.0 in my.cnf). Check with netstat -na|grep 3306.
Figure out the host ip that your container can reach. So check the IP of the container: docker inspect container-id, find the IP, and replace the last part with .1, that should be the IP of your host in the containers own network. I.e. 172.17.0.1 (it can be considered as fixed IP, for dev environment it's ok)
So most likely that this is what you need: 172.17.0.1:3306

Fedora Chrome, can't access localhost or 127.0.0.1 when offline

I have my local httpd or Apache open. It works when online, but not when offline... How can I make it work?
This is a bug in Google Chrome. Starting Chrome with --enable-ipv6 fixes it.
See http://code.google.com/p/chromium/issues/detail?id=42058 for details.
127.0.0.1 should work regardless of what's in /etc/hosts
If you do an ifconfig do you see the lo loopback interface?
This may be a better question for superuser or serverfault
In Ubuntu, when offline you can use the ifconfig command manually to configure the Ethernet card. For example, set eth0 to an IP address. Then you can access localhost.
For example:
ifconfig eth0 192.168.1.101
Has it anything to do with the etc/hosts file? Do you have localhost defined in there?
If not, your machine may be using DNS to resolve localhost, where if it is set in the host file, you should be able to access it while offline.
this is what you are looking for. Every time you log in to Fedora you have to start Apache
Therefore you need to execute the following commands
sudo service httpd start
You may also run into problems in the future if you need to use phpmyadmin
enter image description here
Cannot log in to the MySQL server
mysqli::real_connect(): (HY000/2002): Connection refused
Remember to use the following command after installing phpmyadmin after each login
sudo systemctl start mariadb