Question

Create a Database on DigitalOcean and connect to it externally (not on the same datacenter)

Posted December 10, 2015 3.9k views
DigitalOceanPython

I’ve an instance server running (Scheduled) a scrapy application on another cloud service, also have another instance on DigitalOcean running the user interface (Flask Application to be precises) with database configured, How can i connect database on Digital Ocean to the Scrapy application running on another cloud server?

Note: The main reason is to allow the data scrap by the scrapy to be inserted into the database on digital ocean, please how can i achieve this. Already have mysql database install with phpmyadmin on DigitalOcean

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

By default MySQL does not allow remote connections and does not include a user account with permissions to reach the database from the outside. This can be adjusted fairly easily.

1.) In /etc/mysql/my.cnf modify the bind-address variable by either 1.) commenting it out or 2.) changing it to 0.0.0.0. Doing either of these will now allow outside connections.

2.) Next you’ll need a user that is authorized to access the database from a remote IP.

GRANT ALL ON database_name.* TO user@xx.xxx.xx.xx IDENTIFIED BY 'your_password'; 

the xx.xxx.xx.xx should be the remote IP address you will be accessing the database from. This can also be set as a wildcard to allow the user acccess from any IP but generally this is not a good idea unless the server connecting to the database has a dynamic IP or cannot be predicted for another reason.

  • Thanks @ryanpq ive comment it out but i can’t connect to it from outside.. every attempt to login using

    mysql -u root -h xx.xxx.xx.xx -p
    

    hang up after supplying my password. i’m missing anything, xx.xxx.xx.xx is the IP address of the other server.

Submit an Answer