How to access MySQL Database on a Bluehost server remotely through Python

Question:

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)
Asked By: DonutGaz

||

Answers:

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)

  1. Log into cPanel and click the Remote MySQL icon, under Databases.
  2. Type in the connecting IP address, and click the Add Host button.
  3. Click Add, and you should now be able to connect remotely to your
    database.
Answered By: Bert
  1. Log in your bluehost account
  2. Click on Advanced
  3. Click the Remote MySQL icon, under MySQL® Databases category DATABASES.
  4. 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
  5. You should now be able to connect remotely to your database
  6. Remember that you have to create user with the permission for the database.
Answered By: user3572376
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.