MySQL in XAMPP not allowing remote connections - php

After following some online tutorials, allowing wildcard (%) connections to the user, assuring that the port and firewall allow connections, and comparing the login info, I'm at a complete loss recving MySQL error 111.
The script I'm using to connect [PHP]
$connection = mysqli_connect('remotehost', 'user', 'pass') or die(mysqli_connect_error());
mysqli_select_db($connection, 'db');
I believe everything is in order, isn't it?
What should my next step be?

Related

PHP times out connecting to Cloud SQL instance

Here is my code for PHP for connecting to the database, a Cloud SQL instance for MySQL:
define('DB_SERVER', '192.0.0.1');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_NAME', 'db');
$db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME) or die(mysqli_connect_error());
Obviously the DB_SERVER is not the actual IP address, nor are the credentials, but I did put in a dummy one to see if I needed to add anything like cloudsql:/ or jdbc:// like you do in Java.
I did authorize the IP address for the webserver on Cloud SQL, but all it returns is a Connection Timed Out error; What can I do to fix this?
I'm certain that the credentials are correct, and that I can connect from other authorized IP addresses, as I have been able to access from another account & multiple IP addresses through the MySQL workbench.
Solved:
For anyone using Siteground's services, make sure to add 0.0.0.0/0 as the accepted IP addresses if you're using public IP authorization. Then find what IP's are connected when you refresh the php page by running this right after the page is refreshed:
SELECT host FROM information_schema.processlist WHERE ID=connection_id();
It should give you multiple IPs, and check them online using an IP locator to see if they match the location of the Siteground's services. Remove 0.0.0.0/0 and add that IP address to Google Cloud SQL.

MySQL connect failed. Can't connect to MySQL server on 'http' (4)

I try to connect my android application using JSON Parser to the web hosting. But whenever I try to connect (even just open using url in the browser) I will get the error message.
<?php
$dbHost = 'http://sql4.000webhost.com/localhost';
$dbUser = 'a6410240_cbetTD';
$dbPass = 'xxxxxx';
$dbName = 'a6410240_cbetTD';
$conn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName,$conn);
?>
This is my database.php file. The full error message is
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'http' (4) in /home/a6410240/public_html/database.php on line 8.
I have tried change the $conn but still it didn't worked for me.
Thanks
If your database and application is on same server then use "locahost" in $dbhost.
And if your database and application is on different servers then you need to use IP address or hostname in $dbhost and the database user should be added on database server provided with required privileges.
The problem you are having was already mentioned in one of the comments, this one to be precise.
For your solution to work, all you need to do is omit the part http:// at the beginning and probably /localhost at the end.
The host is only the domain you are referring to. In this case sql4.000webhost.com. With /localhost you tried to already connect to a database, although your configured database is supposed to be a6410240_cbetTD.
MySQL use TCP port 3306 by default
($dbport) and hostname or IP address ($dbhost). For LAMP (Linux-Apache-MySQL-php) you can find a lot of tutorials.
Usually MySQL server listens internal port (which can't be reached via Internet) for security purposes.
If you familiar with docker, you can simply download examples of LAMP solutions from hub.docker.com.

mysql_connect(): Connection refused

I was just wondering if it was possible for certain databases to block SQL accesses through mysql_connect. I recently downloaded XAmpp and created a SQL database using my own computer as a local host and wrote a PHP file that accessed that database.
However, when I tried to change the username and host settings so that Xampp would run the PHP files that would then connect to the external SQL database of a free hosting site that I'm trying to use (biz.co.nf), I got the following error message:
Warning: mysql_connect(): Connection refused in /Applications/XAMPP/xamppfiles/htdocs/...
Right now I'm thinking either:
My login credentials to that database are incorrect, or
Somehow the host blocks SQL accesses from external users, but if I were to load my php code into the server using FileZilla, it should work okay?
Please let me know if this is the case.
I'm also fairly certain I have the right login credentials.
Here's what I have:
$host = "fdb13.biz.nf";
$username = "1764941_login";
$password = ________;
$db_name = "1764941_Login";!
$tbl_name = "Members";
//Connect to server
mysql_connect($host, $username, $password)or die("Cannot Connect!");
mysql_select_db($db_name)or die("Cannot select Database");
with my server settings according to my website...
Of course, I omitted my password.
Connections are refused from remote locations to MySQL for security reasons. You can add your IP Address to enable MySQL to listen from your database by following the instructions in this link - Cyberciti biz tips on enabling remote access to mysql database server In your case, add the IP address of the location where your PHP script.
I would also say that
mysql_connect
is deprecated in PHP. Use mysqli instead. Check the comments in the link - PHP original MySQL API

mysql connecting to remote host fails

In my script on de webserver I'm trying connect to mysql through the (good old) mysql_connect() to an ip (db server) in the same network.
MySQL keeps throwing me the error:
Access denied for user ''#'localhost' to database 'dbname'
This seems like the db is being searched on the localhost (webserver) instead the IP I've entered (db server).
I've checked the my.cnf and can't find a bind-address or whatever.
When I connect through mysqli_connect(), the connection can be made, so there shouldn't be a firewall issue I guess.
Reason I'm still using mysql_connect is because i'm transferring a big website to a new server, and there is no time to change the function through all the script.
Anybody familiar with this problem and got any suggestion? Thanks in advance!
Update: piece of code
$link = mysql_connect("12.34.56.78", "username", "password");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('dbname', $link);
if (!$db_selected) {
die ('Can\'t use dbname : ' . mysql_error());
}
Make sure you have "SQL safe mode" disabled in your php.ini file.
From the documentation of mysql_connect on the server parameter:
server
The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.
If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. In SQL safe mode, this parameter is ignored and value 'localhost:3306' is always used.
Similar filtering applies to the username and password parameters:
The username paramter defaults to the name of the user that owns the server process and password defaults to an empty string.
You can read more on SQL safe mode from here:
http://us1.php.net/manual/en/ini.core.php#ini.sql.safe-mode
Looks like the php is searching on the localhost but is using the username "". I think you have a problem with your user/pass combination and are also putting the ip address in the wrong place. Could you paste your code?

Connect to Amazon RDS with PHP

I am trying to connect my RDS Instance with my PHP connection file.
This is what I have in my file:
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'User Name');
define('DB_PASSWORD', 'Password');
define('DB_DATABASE', 'DATABASE');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
I replaced localhost with my endpoint (rds thing) url, username and password with my RDS Instance user and pass and database name the one I've set when I created the instance. But it doesn't seem to work.
Is there anything else I have to do that I am not aware of or should it work?
RDS instances do not have a static IP address attached to them, you always use the endpoint for the host. For example:
database1.jlsdfjhgsdf.us-east-1.rds.amazonaws.com
If you are connecting to the instance with a username other than the root database account, you will need to grant the user privileges.
Check security group settings. If you are connecting from another EC2 instance on Amazon you will need to attach that security group. If you are trying to connect from outside AWS, you will need to whitelist the IP address you are accessing from.
Some ideas:
Try using the actual IP of the instance, then it should work.
Did you authorized access to your DB instance?
You may want to have a look at Get Started with Amazon RDS to properly setup your RDS instance
I was facing a similar issue whilst trying to connect an EC2 Apache server using PHP to the RDS MySQL instance.
Weirdly I could establish a connection via CLI - once in mysql running status will tell you which user youre logged in with, plus the port, server name etc.
Turned out some AMI images have SELinux enforcement - meaning the apache server cant send network requests as pointed out by this gentlemen (http://www.filonov.com/2009/08/07/sqlstatehy000-2003-cant-connect-to-mysql-server-on-xxx-xxx-xxx-xxx-13/)
Other points:
Make sure inbound ports are set for your RDS DB
In MySQL make sure the host is set to '%' as opposed to localhost
Always use the endpoint string to connect as the RDS IP changes
I was recently having a lot of trouble with this also but was able to fix it. I made sure my security groups (for the RDS and for EC2) were allowing each other. I was able to run my script from the terminal and connect to my database also from the terminal, but I couldn't get the script to run/connect to MySQL from a browser. It turns out I did not have mysql-server installed-- once I installed that and restarted httpd and mysqld it worked like a charm.
This article is what led me to installing mysql-server and the service starts/restarts. Hope it helps! -- http://www.rndmr.com/amazon-aws-ec2-easy-web-serverset-up-guide-with-a-mac-and-coda-2-256/
Just accepts all incoming connections.
I also had the connection problem between the ec2 (apache + php server) and the RDS (Mysql server) when following the tutorial at http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateDBInstance.html.
I solved it by using the double quote when specifying the connection value while the guideline is using single quote.
define('DB_SERVER', "localhost");
define('DB_USERNAME', "User Name");
define('DB_PASSWORD', "Password");
define('DB_DATABASE', "DATABASE");
I was trying to connect to my DB instance using node-mysql. I found that I the endpoint that RDS provided me with did a DNS lookup. Followed that up and changed the URL to that one. I was only able to connect with mysql via command line until then. When I changed it to the resulting endpoint after the lookup, node-mysql was finally able to connect.

Categories