Topic: PHP wont connect to mysql.

Im running Apache/2.2.3 and PHP/5.1.6, but PHP wont connect to MySQL.

phpmyadmin says this: #2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)

But in php.ini the default mysql socket is set to /var/lib/mysql/mysql.sock. Also, i can connect to mysql via cmd line.

See:

[root@host php-5.1.6]# mysql -u root -p mysql
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 5.0.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

It was working, until i recompiled PHP to have GD enabled. :\ (GD works now, but MySQL doesnt, and it is enabled).

http://host.uploadit.biz/phpinfo.php
^^PHP Info

Re: PHP wont connect to mysql.

Your PHP Info says it's enabled... are you sure the service is started (and starting at startup)

3 (edited by Ruckus 2006-10-09 19:57)

Re: PHP wont connect to mysql.

elbekko wrote:

Your PHP Info says it's enabled... are you sure the service is started (and starting at startup)

Yes, i can connect to it from cmd line. Tho again:

[root@host ~]# ps ax | grep mysqld
 3244 pts/0    S      0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --pid-file=/var/run/mysqld/mysqld.pid --log-error=/var/log/mysqld.log
 3280 pts/0    Sl     0:00 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock
15185 pts/0    R+     0:00 grep mysqld
[root@host ~]#

This is my my.cnf:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[client]
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

4 (edited by Ruckus 2006-10-09 20:03)

Re: PHP wont connect to mysql.

Ah i see the problem, even tho i have in php.ini

mysql.default_socket = /var/lib/mysql/mysql.sock

phpinfo still says: MYSQL_SOCKET     /tmp/mysql.sock

And, the php.ini path as shown in phpinfo is correct :\


Fixed the problem by placing a symlink in /tmp pointing to /var/lib/mysql/mysql.sock