mysql conection problem
Hi
I've just installed a binary version of mysql 4.0 downloaded from mysql.com. Installation went ok and I can connect to the database. But my dbconnect isn't working. error printed to PHP page reads. Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/html/emailer/dbconnect.php on line 3 I cannot connect to the database because: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) The password and username are ok and I can connect using a terminal. I've tried rebooting but no joy. Is this something to do with configuring PHP as I used a binary distribution and not an RPM? If so what change do I have to make. Or where can I read up some more. Here's my dbconnect $db=mysql_connect ("localhost", "usrnme", "psswd") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db("dbase",$db); Cheers |
Re: mysql conection problem
Quote:
What happens when you do a "telnet localhost 3306". $ ps -ef |grep mysql Kill all of them and then start mysql using "service mysql start" (on redhat) |
Try it without the password. eg
mysql_connect ("localhost", "username"); |
Have you loaded the mysql-php patch rpm?
urpmi php-mysql Not loaded by default Php will not connect with mysql without this. have you modified php.ini at include path erase to read only include_path ='./'' Reload your browser. check your mysql passwords work in a terminal Run a text file in your browser with only the line <? phpinfo() ?> Seein the phpinfo at the mysql after the GETEXT if you have the mysql .sock listed it should be in /var/lib/mysql/mysql.sock |
Thanks for your help guys. By checking this stuff I have increased my understanding alot but have come to the end of things I can check but still cant get php to connect to mysql.
I've included the results of your suggestions below. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: The error is Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' but mysql.sock is in /tmp/mysql.sock Where do I make the change so PHP looks for the mysql.sock in the right place? I couldn't see it in php.ini :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: The server is definatly running [root@localhost /]# ./usr/local/mysql-standard-4.0.20-pc-linux-i686/bin/mysqladmin -u root -ppsswrd version ./usr/local/mysql-standard-4.0.20-pc-linux-i686/bin/mysqladmin Ver 8.40 Distrib 4.0.20, for pc-linux on i686 Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 4.0.20-standard Protocol version 10 Connection Localhost via UNIX socket UNIX socket /tmp/mysql.sock Uptime: 18 min 21 sec Threads: 1 Questions: 1 Slow queries: 0 Opens: 6 Flush tables: 1 Open tables: 0 Queries per second avg: 0.001 [root@localhost /]# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: telnet localhost 3306 result [root@localhost simon]# telnet localhost 3306 Trying 127.0.0.1... Connected to localhost (127.0.0.1). Escape character is '^]'. 0 4.0.20-standard&^*RB0jF,Connection closed by foreign host. [root@localhost simon]# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Tried without the password but it didnt work. urpmi php-mysql is apparently installed [root@localhost simon]# urpmi php-mysql Everything already installed [root@localhost simon]# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Quote" have you modified php.ini at include path erase to read only include_path ='./'' " would that be this include path? ; UNIX: "/path1:/path2" ; ### MDK include_path = ".:/usr/lib/php/:/usr/share/pear/" ; I tried include_path = "./usr/lib/php/:/usr/share/pear/" (without the first colon) and include_path = "./" As php is working OK I didn't think it was this include path so put it back to normal but cant see another include_path in php.ini Here is the mysql section of php.ini \\\\\\\\ start //////// [MySQL] ; Allow or prevent persistent links. mysql.allow_persistent = On ; Maximum number of persistent links. -1 means no limit. mysql.max_persistent = -1 ; Maximum number of links (persistent + non-persistent). -1 means no limit. mysql.max_links = -1 ; Default port number for mysql_connect(). If unset, mysql_connect() will use ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look ; at MYSQL_PORT. mysql.default_port = ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. mysql.default_socket = ; Default host for mysql_connect() (doesn't apply in safe mode). mysql.default_host = ; Default user for mysql_connect() (doesn't apply in safe mode). mysql.default_user = ; Default password for mysql_connect() (doesn't apply in safe mode). ; Note that this is generally a *bad* idea to store passwords in this file. ; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password") ; and reveal this password! And of course, any users with read access to this ; file will be able to reveal the password as well. mysql.default_password = ; Maximum time (in secondes) for connect timeout. -1 means no limimt mysql.connect_timeout = 60 ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and ; SQL-Erros will be displayed. mysql.trace_mode = Off \\\\\\\\ end //////// I tried adding /tmp/mysql.sock to ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. mysql.default_socket = /tmp/mysql.sock but no joy. Mysql passwords definatly work in a terminal and there isn't a typo in the dbconnect file. Here's the mysql relevant bit from phpinfo(). MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version 4.0.18 MYSQL_MODULE_TYPE none MYSQL_SOCKET /var/lib/mysql/mysql.sock MYSQL_INCLUDE no value MYSQL_LIBS no value MYSQL_SOCKET still doesn't read /tmp/mysql.sock even after change php.ini default socket name. Cheers |
I've managed to solve the problem using a symbolic link from /var/lib/mysql/mysql.sock to /tmp/mysql.sock
Would prefer to know what the 'correct' solution is though. Cheers |
Did you not run the mysql rpm from 10.
you appear to have the standard redhat configuration location of the sock.? Perhaps, you downloaded an new mysql? |
yep Barrys plz check the first entry, first line of this thread. Cheers.
|
RTFM
A.4.5 How to Protect or Change the MySQL Socket file /tmp/mysql.sock The manual, if you don't have it is downloadable or online. The chapter you want is: http://dev.mysql.com/doc/mysql/en/Pr...ysql.sock.html |
All times are GMT -5. The time now is 04:50 PM. |