1

This code runs from my Mac, but it is not running from a hosted server. The error message is:

Tue, 11 Jun 2013 14:46:48 -0700
Remote host: my_remoteserver.com
Remote user: my_user
Remote db: my_remotedbname
mysqli Failed to connect to MySQL: Access denied for user 'my_user'@'localsystem.com' (using password: YES)

For some reason the local apache/php system is attaching "@localsystem.com" to my userid. What configuration parameter can I adjust to prevent that?

When run from my Mac, the output is, as expected:

Tue, 11 Jun 2013 18:03:41 -0400
mysqli Connection was OK!
Show databases returned 2 rows.
information_schema ()
my_remotedatabase ()

the code:

<?php
$hostname = "my_remoteserver.us";
$user = "my_user";
$password = "_today0613";
$dbname   = "my_remotedbname";

echo date(r, time());
echo "Remote host: " . $hostname . "<br/>";
echo "Remote user: " . $username . "<br/>";
echo "Remote db: " . $dbname . "<br/>";


$con=mysqli_connect($hostname,$user,$password,$dbname);

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "mysqli Failed to connect to MySQL: " . mysqli_connect_error();
  } else { echo "mysqli Connection was OK!<br />\n";}

/* Select queries return a resultset */
if ($result = $con->query("SHOW databases")) {
    printf("Show databases returned %d rows.<br />\n", $result->num_rows);

    /* fetch object array */
    while ($row = $result->fetch_row()) {
        printf ("%s (%s)<br />\n", $row[0], $row[1]);
    }
    /* free result set */
    $result->close();

    }
$con->close();
?>
4
  • What is localsystem.com ?? Can you echo the connection variables to ensure they are what you expected before you connect? Maybe one got changed somehow.
    – SH-
    Jun 11, 2013 at 22:14
  • updated code in original post as well. I added code: echo "Remote host: " . $hostname . "<br/>"; echo "Remote user: " . $username . "<br/>"; echo "Remote db: " . $dbname . "<br/>"; - and it returns the userid without the @localsystem.com Jun 11, 2013 at 22:27
  • Its possible that that system has a config somewhere to auto append the @localsystem.com?
    – SH-
    Jun 11, 2013 at 22:35
  • yes, most certainly. But where? and how do I override it, or change it? Jul 14, 2013 at 13:17

2 Answers 2

0

Have you got remote access enabled for the user? If not, login as root or another administrative user to your mysql and issue:

GRANT ALL PRIVILEGES ON *.* TO  ‘USERNAME’@‘IP’  IDENTIFIED  BY  ‘PASSWORD’;

Change:

The *.* stands for All schemas, all tables.. Specific access to one schema (recommended):

SchemaName.*

username to the user that you want access to

ip Change to the IP that the server is on

identified by password substitute password for the users password.

Then issue:

FLUSH PRIVILEGES

or restart the entire mysql service

4
  • As I said - this runs from my Mac here on my desktop, connecting to the remote server "my_remoteserver.com" - I decided to test it by putting it on another server I help manage - call it "localsystem.com" - and that system is inserting its own "@localsystem.com" to the userid for some bizarre reason. Jun 11, 2013 at 22:22
  • and I do not want to add the @localsystem.com to the userid because the database may be accessed from a number of different remote servers during development and production. Jun 11, 2013 at 22:32
  • Help! can anyone help me with this problem - I've moved on to other things, but still need this to work correctly. The issue is not solved by adding user@remotesystem, I don't think. The issue is that my mysql server is appending @localsystem to the UID. That is the behavior I'm trying to change. Jul 27, 2013 at 22:13
  • Are you using the FQDN? or the IP to identify the system?
    – Daryl Gill
    Jul 27, 2013 at 22:15
0

Ok, this is a problem. Likely to be the cause.

$con=mysqli_connect($hostname,$user,$password,$dbname);

In your debugging it uses.

echo "Remote user: " . $username . "<br/>";

These need to be the same variable. The system by default is probably using @localsystem.com if it is not filled.

4
  • It is not clear to me what you are saying. PHP mysqli_connect is using the remote $hostname properly, but for some reason it is adding @localhost to the username. This is the barrier I cannot get over or around. This is new behavior for me, some setting that I cannot discover. Aug 19, 2013 at 11:21
  • In the debugging statement you have a different variable name. probably mismatched names somewhere. So you are using the default somehow.
    – SH-
    Aug 19, 2013 at 19:57
  • Well. Duh. Thanks for pointing that little item out. I did not even see it. However, one of the other fellows added some debugging lines, and he might have added it incorrectly ($user/$username). I have opened a ticket with HostGator, and it seems adding the @localhost is a default in cPanel, and they will offer no way to get rid of it. So I just have to figure out how to work around it. This default is causing problems in other scripts as well, and it did not work this way in a Plesk environment on another hosting service. Aug 20, 2013 at 1:42
  • As is often the case here, we eventually solve things on our own. I have solved this mystery, or come close. Aug 21, 2013 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.