Lost connection to MySQL server at 'reading initial communication packet [duplicate] - python

This question already has answers here:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
(40 answers)
Closed 9 years ago.
I want to establish a connection between my local machine and MySQL database server via Python.
Can someone tell me how to "bind-address with localhost"?

Can someone tell me how to "bind-address with localhost"?
This is a MySQL configuration directive.
Edit the global my.ini file, in the [mysqld] section:
[mysqld]
# -- various other settings
port = 3306
bind-address = 127.0.0.1
# -- other settings
Save this file, and then restart your server.
Edit
If you want to connect to your local Windows instance of MySQL, simply use 127.0.0.1 as the server's address.
If you want to connect to your remote server, the one running Linux then it is a bit complicated:
First, make sure MySQL is listening on the public IP of the Linux server. Change the line bind-address = and set it to the public IP of your server.
Make sure port 3306 isn't blocked by any firewall.
The user that you use to connect to the server needs to have rights to connect from a remote IP. By default, users are only given rights to connect from localhost - in other words they can only connect if the program is running on the same machine as the server itself.
To grant a user access from a remote IP, run this command from the mysql> shell when logged in with the MySQL root user:
GRANT ALL on somedb.* to someuser#8.8.8.8 identified by 'somepassword';
If you want to grant access to someuser from any remote IP:
GRANT ALL on somedb.* to someuser#% identified by 'somepassword';
After those steps, make sure to restart the MySQL server so it will read the changes in the configuration.

Related

PostgreSQL Connection issues- Python

i want to connect a python code with a database localized in a Google Cloud Platform PostgreSQL database. I've been running this code and this working correctly, but recently i chaged me server to a VPS provided by a host. Now when i try to connect to the database with python3 i receive the follow message:
Psycopg2.OperationalError: could not connect to server: Connection timed out
Is the server running on host "35.199.90.49" and accepting
TCP/IP connections on port 5432?
I have authorized the IP of the server in the Google Cloud Platform, i tried to open all IPv4 address too, but nothing is working. I changed the /XX from IPv4 for my server. I disabled the firewall of the server. Nothing is working but when i connect with the psql command at ubuntu server, the database connection is okay.

Can't connect to MariaDB server remotely using TCP

I know this kind of a question has been asked for a thousand times, but I still need to, because I assume that I'm doing everything right here and internet hasn't helped my out.
So I'm trying to remotely connect to my MySQL server (hosted by MariaDB 10.3.29 on Raspbian 10, Raspberry Pi 4). I've been trying to connect by using address 192.168.1.4 on my phone, another computer on another network, by using mysql server command line on a Windows PC and even on iOS using a QueryDB app.ยด
The exact error message I'm getting is:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.4:3306' (10060)
Config file:
/etc/mysql/mariadb.conf.d/50-server.cnf
has this to be able to connect from any IP:
bind-address = 0.0.0.0
as I think it should.
Also my ufw has mysql allowed, and port 3306 that I'm using, is allowed from anywhere.
I've done this:
GRANT ALL ON *.* TO 'user'#'%' IDENTIFIED BY 'my_pass';
FLUSH PRIVILEGES;
And to be sure I've checked that with
SELECT User, Host FROM mysql.user;
All seems to be OK. I still can't connect remotely. Of course I can connect from localhost, like another computer on my LAN.
I've also opened port 3306 on my ASUS router settings like this:
ASUS router port forwarding
Is that like it should be?
I really can't figure out anything causing this problem. According to information I've gathered, everything should be working. Thanks!
Ok, so after searching for three days I got this.
The problem wasn't with the MySQL but with the Apache. I needed to forward Apache's port 80 to connect to my Public IP address, not local of course.
So it works now!

How to find the port number for a remote server?

I'm trying to set up SSH Python interpreter on Pycharm. In the wizard, it is askin for:
Host
Username
Port
I know the the name of my remote workstation and my username. But where can I get the port number from? does it require settings of Pycharm on remote server?
Instructions are not clear.
I have W10 on both sides.
https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html
On your Windows 10 remote server you have to enable/install an SSH server. Windows does have a native one, I saw that you can also use OpenSSH now.
And your SSH server should run on port 22 by default.
Try default port 63342 of pycharm besides ssh connection port on 22 :
https://www.jetbrains.com/help/pycharm/settings-debugger.html
You have to setup an SSH server on your remote machine in order to connect to it.
See: https://phoenixnap.com/kb/ssh-to-connect-to-remote-server-linux-or-windows
Once you have done that, the host will be the address of the remote machine, the username and password will be the credentials of a user that exists on the remote machine and the port will be a number that you have chosen when you were setting up the SSH server (22 by default).

AWS + MongoDB : How to connect to mongo server on AWS linux instance?

I launched an AWS linux instance and installed and ran mongo as instructed here. The mongo service is running and accepting connections on 27017. However, when I go to the server publik dns with port 27017 the server does not respond and I don't see the default mongo message.
I am trying to run a Python(Flask) server on another instance and trying to connect to the mongo server using the private ip, but the connection does not happen. I get this error message on the terminal :
pymongo.errors.ServerSelectionTimeoutError: xxx.xx.xx.xx:27017: [Errno
111] Connection refused
Is this not the right way to use mongo db on aws ? If this approach is feasible, what is causing the connection to not happen ?
All inputs appreciated, much thanks!
It is possible that your mongodb is configured to only accept connection from local host. Edit /etc/mongod.conf file to comment out the line that bindIP like in the example below -
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

sqlalchemy connect to VPS database

I am trying to connect to VPS mysql database from my PC. I use sqlalchemy framework, but I need establish SSH tunnel before connection.
Usual way, when web app run on VPS:
create_engine('mysql://user:pswd#localhost/dbname')
How can I connect to this database from another PC. Assume there are connections credentials: IP, username, password
Your MySQL server is listening to local connections only. To make it listen to outside connections:
Edit the /etc/mysl/my.cnf file
Comment out the line bind-address = 127.0.0.1
Restart mysqld

Categories