NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysql connection

William Klein willie at pdfsystems.com
Fri Nov 12 16:32:31 EST 2010


Yeah I understand that.  I can connect from the apache server with

mysql -u root -h 192.168.199.31 -p

 

but the php connect fails with 

 

Warning: mysql_connect() [function.mysql-connect
<http://192.168.199.30/function.mysql-connect> ]: Can't connect to MySQL
server on '192.168.199.31' (13) in /var/www/html/order/test.php on line 2
Could not connect number2003 error Can't connect to MySQL server on
'192.168.199.31' (13)

 

Error 2003 is permission denied and so is 13 but I'm using the same user:

Test code:

<?phnk = mysql_connect('192.168.199.31:3306','root','xxxx');

if(!$link){

        die("Could not connect number". mysql_errno()." error "
.mysql_error());

}

?>

 

Strange, which is why I was looking at the php complile.

The phpinfo() command does mention the mysql sock in /var/lib/mysql but no
mention of a tcp connection I thought perhaps there was a compile parameter
I'm missing.

 

From: Rob Marscher [mailto:rmarscher at beaffinitive.com] 
Sent: Friday, November 12, 2010 4:08 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] mysql connection

 

On Nov 12, 2010, at 4:02 PM, willie klein wrote:

Setting up a new server and finally splitting my apache server and mysql
server into 2 virtual boxes.

For some reason I can't connect to the remote server with php but I can
connect with mysql command line.

I think it must be some way I compiled php, tried just using rpms also.

 

I'm not sure it's your php compilation.  What about mysql permissions?  Can
you connect via mysql command line running on your apache server to the
mysql server?  Also want to make sure the port is open on the mysql server
(usually 3306) and that the mysql server doesn't have "skip-networking" in
it's my.cnf.  The permissions for mysql users includes the hostname that
user is allowed to connect from.  If you want to open up the permissions for
the user so they can connect from any server, you want to do something like
this:

 

CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT USAGE ON *.* TO 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON `dbname` . * TO 'username'@'%';
FLUSH PRIVILEGES;

 

The % wildcard allows the user to connect from any host.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20101112/458f0905/attachment.html>


More information about the talk mailing list