![]() |
Can't connect to mysql from php script
I am trying to setup a LAMP server to practice database driven web development.
System Confiruration: Apache 2.2.6 php 5.2.4 mysql 5.0.45 The mysql command line interface works fine. Isses: Apache and php works but when i try to connect to a mysql database the html and php works but the mysql does not work - no error message displayed. html files with embedded php scrips processes only the html code - no php processing. php scripts process both html and php. |
Do you have the php-mysql package installed? That's the first thing I would check. What's the complete listing of php and mysql related packages you have installed?
|
Quote:
Additional info --------------- <?php $mysqli = mysqli_connect('localhost', 'mysql', 'password', 'testDB'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } ?> Error Message: Connect failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) --------------- I ran the phpinfo() function from a script and found the following listed under the mysql section MYSQL_SOCKET /var/lib/mysql/mysql.sock but there is no /var/lib/mysql directory on the system when I typed: ps xa | grep mysqld I get: --------------------------------------------------- 1900 ? S 0:00 /bin/sh ./bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid 2005 ? Sl 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306 3450 pts/0 S+ 0:00 grep mysqld ----------------------------------------------------- I found: --socket=/tmp/mysql.sock in the output ls -l /tmp/mysql.sock srwxrwxrwx 1 mysql mysql 0 2008-02-22 22:23 /tmp/mysql.sock I also found this line in /etc/my.cnf socket = /tmp/mysql.sock I don't know why the phpinfo() function show MYSQL_SOCKET /var/lib/mysql/mysql.sock I don't know where to go from here Thanks |
Assuming you're on Fedora (since this is a Fedora sub-forum), use
yum install php-mysql as root from the command line. If you use a GUI, there is an add/remove front-end available too somewhere. Edit Note you can list php packages with yum list installed php* and sim. for mysql |
or you could type "rpm -q --all | grep php" without the double quotes
|
rpm q all - response
Quote:
What does this say about my php/mysql configuration? # rpm -q --all | grep php php-mysql-5.2.4-3 php-ldap-5.2.4-3 php-common-5.2.4-3 php-5.2.4-3 php-pdo-5.2.4-3 php-cli-5.2.4-3 Thanks |
Ok, that means that you have the right packages installed. In your other post about mysql.sock, you mention that your my.conf has the right location for the mysql.sock but running phpinfo() gives the wrong location. I'm no expert, but I'm suspecting now that there might be a wrong line in your php.ini file (/etc/php.ini) There's a line that starts with "mysql.default_socket="
Maybe you can check that line to see if it doesn't say the wrong thing there? |
chmod user.group
I had a case with a Fedora 6 installation upgraded to Fedora 8, leading to a similar problem with a MySQL socket. I have tried to reinstall MySQL but that didn't correct the problem.
In the end it turned out that the current MySQL installation is using the 'root.mysql' combination of user.group, but the /var/lib/mysql directory and it's contents where set to belong to 'mysql.root'. Just the other way around. That's a subtle difference, but enough to not allow MySQL to create a socket file in that location. Using chmod to set proper user.group values did solve the problem in my case. Hope this helps, Regards, SIMP Linux Archive |
| All times are GMT -5. The time now is 01:27 PM. |