0

I have two computers connected on the lan and i want to simulate a client server type of configuration .So suppose i have pc1 acting as the server and pc2 as the client.I created a database on the pc1 and kept the registration form on the pc2 .so whenever i execute the registration script i get the following error.

Failed to connect to MySQL: Host '192.168.2.6' is not allowed to connect to this MySQL server

This is the registration code where i have replaced database host with the ip address of pc1(server) which is running xampp .

<?php

define('DB_HOST', '192.168.2.7');//192.168.2.7 is the ip address of my server.
define('DB_NAME', 'hello');
define('DB_USER','root');
define('DB_PASSWORD','');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());

Do have i have to make any changes in mysql config file in xampp or if i have to make changes to the database host name.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
user2218550
  • 147
  • 1
  • 2
  • 11
  • 1
    Checkout this thread http://stackoverflow.com/questions/13731514/host-is-not-allowed-to-connect-to-this-mysql-server-when-making-a-local-connecti – sofl Mar 06 '14 at 17:36

2 Answers2

1

If the server is on your local computer, try using localhost as the ip address.

To grant access to computer with ip: 192.168.2.7:
GRANT ALL ON *.* TO root@'192.168.2.7'

To grant access to all computer no matter what their ip is:
GRANT ALL ON *.* TO root@'%'

Krimson
  • 7,386
  • 11
  • 60
  • 97
  • how do i do this is xammp on windows – user2218550 Mar 06 '14 at 17:43
  • You cant do it using xammp, since xammp is a webserver which installs mysql. Its not a mysql interface. To make it easier, try using mysqlWorkBench: http://dev.mysql.com/downloads/tools/workbench/ – Krimson Mar 06 '14 at 17:45
0

you need to provide access to all hosts through wildcard by using following query

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password';

Refere to Documentation for more info