I just launched a phpMyAdmin droplet as a 1 click app. But I cannot connect to it from PHP on my local machine.
I’ve got it set up like so -
// database connection
$db_username = 'user';
$db_password = 'xxx';
$db_database = 'db_name';
$db_host = "123.456.789.100";
// connect to DB
try {
$dbh = new PDO("mysql:host=$db_host;dbname=$db_database;charset=utf8", $db_username, $db_password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage(); die();
}
It works for my other databases, but not 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.
Here’s the result of sudo ufw status
I’ve edited the /etc/mysql/my.cnf file like so -
Then I tried to restart the server and got this error -
So instead, I did a hard reset via the DO interface and I still get the following error: Error!: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
Hi @hansen, thanks for your suggestion. I tried the tutorial and now I get the following error -
Error!: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
I tried googling it and tried a handful of seemingly related tutorials to no avail :( any ideas?
Hi @12monkeys
Almost every one-click-app comes with firewall enabled, so you need to allow access to your MySQL from the outside if you want to use it remotely.
You can run this command to show the status of the firewall:
And run this command to allow access from anywhere to MySQL:
Please setup advanced, long users and password - or only allow connections from specific IP addresses. You can read more about the UFW firewall in this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04