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
Related
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.
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.
I am connecting to a remote server's port 27017 using ssh and then accessing the mongo database on that system. I can successfully connect it via the shell script. However, when I write a python program and try to connect to that system, I am not able to connect. I use the following piece of code:
conn = MongoClient('mongodb://username:password#hostname:27017/database')
I would want to mention that I am accessing the destination system behind a proxy. However, the port 27017 is enabled for my system to connect to the destination system.
conn = MongoClient('mongodb://username:password#hostname:27017/database')
Your hostname is 27017 but the port you enabled is 27107
I’m using tornado and connecting to MySQL using MySQLDB. How I can connect to MySQL using SSL?
If the MySQL server is on the same host as the web server then you don't really need to do this since traffic will not leave that box. You can use an ssh tunnel to encrypt traffic if you'd like. Something like the following should do the trick:
$ ssh <mysql_port>:localhost:<mysql_port> user#mysqlserver.host
That will create a tunnel from your MySQL server to the web server. You can then connect to localhost:port instead of mysqlserver.host:port.
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.