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

December 10, 2015 740 views
DigitalOcean Python

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

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 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 IDENTIFIED BY 'your_password'; 

the 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 -p

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

Have another answer? Share your knowledge.