I have question how can I connect to VPS server and interact with MySQL database using python on my local machine.
I would like to make program using PyQT that connect to my server and update, take sth from db.
I know that there is MySQLdb module but from what I know i cannot connect to VPS server, because in connect method it doesn't take server password argument.
Related
I created a connection to a remote, tunneled MySQL server over the PyCharm GUI in the "Database" menu.
I'm trying to use this connection in the code itself, without connecting manually again to the SQL server and tunelling over SSH in the code.
Is this possible? I couldn't find anything relevant on the internet yet.
Thanks!
I've got an app engine running and I'm struggling to get the MySQL to connect when it has been deployed. It connects fine on my pc running the dev server, but as soon as I deploy I get this error:
OperationalError: (2004, "Can't create TCP/IP socket (-1)")
Could this be because it is not a cloud sql database ? I've fiddled with a few things like firewall rules and dns things but I honestly just don't know where to even start solving this issue. Some research indicated it might be a TCP/IP vs Unix socket issue which does also kind of make sense as I've got another connection to a cloud sql instance which works fine (using a unix socket). It is a python app, any help is appreciated
You need to enable billing for your project to use socket connections in appengine..
I currently have a Python connector script that I run on my Bluehost server locally. In the past, I've tried to run this script remotely, i.e. login remotely with the Python script on my own local machine, but I ended up just running it on the server. In my current situation, I need to run a script every 10 minutes on the server, but I don't have root access, so I can't create a cron job. I can, however, set up a Windows task to run my script every 10 minutes remotely, but when I try, I'm unable to connect to my domain's database. Is there any documentation or work around for this?
Here's my code for connecting to the database remotely:
cnx = mysql.connector.connect(user='database_user',
password='database_password',
host='www.example.com',
database='database_name')
When I try to use this script remotely, I get the following error message:
InterfaceError: 2003: Can't connect to the MySQL server on 'example.com:3306'
(10061 No connection could be made because the target machine actively refused it)
You have to enable access for the IP address of the computer you are trying to access the server from. By default the database server doesn't allow outside connections. You'll do this by logging into your host (Bluehost)
Log into cPanel and click the Remote MySQL icon, under Databases.
Type in the connecting IP address, and click the Add Host button.
Click Add, and you should now be able to connect remotely to your
database.
Log in your bluehost account
Click on Advanced
Click the Remote MySQL icon, under MySQL® Databases category DATABASES.
Type in the connecting IP address the IP that you want be enabled to access bluehost mysql database (eg. your public IP - https://whatismyipaddress.com/), and click the Add Host button
You should now be able to connect remotely to your database
Remember that you have to create user with the permission for the database.
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.
I am trying to get a Python and Tornado environment up and running.
As of now I am able to execute Python scripts and now I am trying to be able to make use of databases as well.
By my understanding Tornado has a MySQL wrapper, and I as of now I have XAMPP installed and I would like to continue using PhpMyAdmin as the GUI for MySQL.
The question I am having is how can I create a connection between MySQL and Tornado?
So that when you use a connection command Tornado will connect to the right MySQL installation and databases, which I of course created with PhpMyAdmin?
From Tornado's documentation:
db = database.Connection("localhost", "mydatabase")
Once you instantiate a connection ( named db in this example ), you can reuse it during your server's lifetime..
If you need to change it dynamically while your tornado server is running, then have tornado "listen" to a specific url_pattern, handled by the appropriate web.RequestHandler, which receives as (GET or POST) arguments your MYSQL connection parameters (host, database, user etc..) and creates a new database connection.
Edit
In newer versions of tornado (>=3.0) the tornado.database module has been removed. It is now available as a separate package, torndb.