By VPFedoraguy
I am trying to connect using this code. $username = ‘root’; $password = ‘password’; $database = ‘localhost’; $mysqli = new mysqli(“104.236.80.149”, $username, $password, $database); if ($mysqli->connect_errno) { echo “Failed to connect to MySQL: (” . $mysqli->connect_errno . ") " . $mysqli->connect_error; } ?> I get this error, and I assume that it isn’t due to my password being incorrect. Failed to connect to MySQL: (2002) No connection could be made because the target machine actively refused it. Is there something I am missing? Same error occurs if I try connecting with new users I make also. I should mention this is a remote connection.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This question was answered by @ryanpq:
Is your database named localhost? I would double-check this value. The reason you are unable to connect to your database is because by default MySQL does not enable remote connections. While your client is on the same server, by using the public IP address the requests are being routed through the public network interface. Instead of:
$mysqli = new mysqli("104.236.80.149", $username, $password, $database);You should try:
$mysqli = new mysqli("localhost", $username, $password, $database);
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.