0

For

$conn = mysql_connect("192.168.0.235", "root", "") or
    die("Could not connect: " . mysql_error());

mysql_select_db("crossdomaintest");

$result = mysql_query("SELECT * FROM testing");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    echo $row[1].$row[2].$row[3]."<br/>"; 
}

mysql_free_result($result);

I am getting

Warning: mysql_connect() [function.mysql-connect]: Host '192.168.0.167' is not allowed to connect to this MySQL server in /var/www/test.php on line 3 Could not connect: Host '192.168.0.167' is not allowed to connect to this MySQL server

And my IP is 192.168.0.168 and I am using LAMP on Ubuntu 10.10 and 192.168.0.235 is using XAMPP on windows 7 i can access all sites on ...235 but not access database from my local-server.

Any ideas?

S L
  • 14,262
  • 17
  • 77
  • 116
  • check to see if you can access the mysql port on windows. – Hossein Mar 20 '11 at 08:42
  • **Currently going offline now** please any effort will be appreciated. – S L Mar 20 '11 at 08:46
  • Use a good database managing program in linux and see if you can connect to windows database using that. Col. Shrapnel is also right, the appropriate privileges on your friend's computer must have been set for the ip of your computer so you can connect to that. (No, i don't know db programs for linux and have no idea where in the windows you should set the privileges.) – Hossein Mar 20 '11 at 09:02

2 Answers2

3

it's not about "how to connect". connecting would be all the same.
it's about how to setup remote server to allow connections from your IP.
do you have root privileges on the db server on 192.168.0.235? if so, you have to run appropriate GRANT PRIVILEGES query on it.
If not - ask a db admin to do that

I'd also advise not to use root user to access remote database. Better create another user and give him appropriate privileges

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • well, i know the root `username` and `password` i am connecting as simply a webrequest. but honestly i don't know a lot of stuff for neetworking – S L Mar 20 '11 at 08:44
  • @experimentX, you are *not* connecting as a web request, MySQL doesn't work that way. You are connecting with MySQL's protocol over TCP/IP. Also, this has *nothing* to do with networking (other than that you are using one). This has to do with the proper permissions on your MySQL installation. Col. Shrapnel is correct. – Brad Mar 20 '11 at 08:49
  • 1
    `GRANT ALL ON * TO 'root'@'%' IDENTIFIED BY 'somepassword';` should do it. Be careful though, you're opening yourself up to trouble. MySQL's protocol is fairly plain-text, and certainly isn't encrypted, unless you connect over SSL, which you aren't doing. Remote root access is generally a bad idea. Instead, you should set up a separate user account that has access only to what you need. – Brad Mar 20 '11 at 08:53
  • @Brad @Col.Shrapnel thanks for info, but i got one question, I can access mysql from terminal, and as well from localhost i.e. apache, and i use `username` and `password` to connect to it, am i still connecting through `TCP/IP` from my localserver to mysqldb? – S L Mar 20 '11 at 08:54
  • That depends. You can, but usually it will use named pipes/sockets instead. If you specify 127.0.0.1 instead of localhost, that will guarantee that you are connecting over the loopback using TCP/IP. – Brad Mar 20 '11 at 08:54
  • @Brad well i was assigned to develop a system that would allow to work offline also. – S L Mar 20 '11 at 08:55
  • 1
    @experimentX ... What does that have to do with your question. If you have a separate question for working "offline", please explain what you need in a new question. Usually if you need a couple systems to function while disconnected and then sync up, you need local servers on each side, and replication. You shouldn't mess with replication at this point. Get the basics down first. – Brad Mar 20 '11 at 08:56
0

Did you change to root user access the host "%"?

Sorry for my english i'm french.

  • Cosmik.
Cosmik
  • 1
  • mean?? i am loggin as a root user there, it's my friend computer – S L Mar 20 '11 at 08:45
  • 1
    @experimentX, each user in MySQL is given a host. Usually, root is only allowed to login from localhost. If you don't grant permissions to the wild-card host (`%`, meaning any-host), then you won't be able to login. – Brad Mar 20 '11 at 08:51