Link to home
Start Free TrialLog in
Avatar of Imaginx
Imaginx

asked on

Cant connect to mysql through the browser, but can connect through terminal ... What am I doing wrong ???

I have a 2 Mac OSX clients running apache & mysql. One is a new installation, one I've been using as a local machine to test web apps for the last 6 months. I haven't made any differences to the functional one, and it started giving me an error message "#2002 Can not log into the MySql Server" when attempting to log in via phpmyadmin .....

The 2nd Mac has newer versions of apache/php/mysql - just finished installing it. Same error. Works perfect if I want to only control mysql from terminal .... Where am I going wrong??


Here is the exact error msg I get if I attempt to run a web app that I've been using at work since Feb
"Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /mfcs_liheap_V3.01/includes/connection.php on line 4"
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Did something change?  PHP upgrade?  The MySQL docs says that usually means the MySQL server isn't running or the port number is wrong.  It could also mean that external TCP/IP access has been turned off or never turned on.  At installation, it is off.  Or that you have no users who have 'anyhost' privileges which allow external TCP/IP access.

Here is a page with some suggestions: http://sourceforge.net/projects/phpmyadmin/forums/forum/72909/topic/3697310

Found this in two places so far:

change the following key in config.inc.file for phpmyadmin
FROM $cfg['Servers'][$i]['host'] = 'localhost';
TO $cfg['Servers'][$i]['host'] = '127.0.0.1';
Then try logining into phpmyadmin again.
Per "DaveBaldwin" post, I agree it sound like the mySQL daemon has stopped on the server, or isn't listening, easiest way to prove it is to open a Terminal window and type:

ps -ef | grep -i mysql
netstat -an | grep 3306 | grep LISTE
ls -l /var/mysql/mysql.sock

If any of the commands fail to return any output you have a problem with the daemon, in which case start by stopping and re-starting mySQL  see: http://www.jonmaddox.com/2007/10/27/start-and-stop-mysql-in-mac-os-x-105-leopard/
Avatar of Imaginx
Imaginx

ASKER

Dave, I have made NO changes whatsoever on the laptop. OSX does it's updates, and the only thing I know I recently allowed it to update was iTunes. (to ver 10(
Also, before I change config.inc.php, phpmyadmin isn't the only the isn't able to connect - any http doesn't connect. I can't access sites I've made and have been working with.
I can however access the dbs/tables in terminal.

Arober11
The first two commands display information, while the third says that folder doesn't exist ...
mysql.sock exists in /tmp  (at least that's the only place I was able to locate it )
Also, I read that link. I have the MySql preference pane already set up. Correct me if I'm wrong, but doesn't it do the same thing ??
Avatar of Imaginx

ASKER

... Almost seems like apache is what won't connect ....

Although, I'm able to run php docs ... ???

... just brainstorming.
It seems like a installation problem. Did you opgrade the OS?
Try backing up your DB files and reinstalling MySQL. Apache manages separately MYSQL and PHP, so its normal if php runs but mysql doesnt.
Avatar of Imaginx

ASKER

I haven't upgraded the OS. And MySql has been working... How could it be an installation problem?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry. I didnt meant that.
I meant that it could be a problem that may be solved by a reinstallation of mysql.
It could always be faster than all the work of knowing the exact problem.
Hi, fairly simple then, in your "my.cnf", probably in /etc/ but not a MAC OS X expert, you'll have a line along the following lines:

socket = /tmp/mysql.sock

and in your /etc/php.ini a:

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

Anyway you can either stop mysql, change one of the lines and re-start the mySQL daemon, else as a temporary fix the following might work:

ln -s /tmp/mysql.sock  /var/mysql/mysql.sock

Note: the file is a Socket (pipe) to the mySQL port, guessing 3306.
Avatar of Imaginx

ASKER

Dave , great article find. That fixed it.... Can't imagine what could have/did change to cause this to happen....

I hated saying that nothing has changed, because I preach that to my users everyday - obviously something has changed !!

Thank you.

Betopa,
I understood what you meant after I wrote that. One of the colleagues in my office was reading this with me & he suggested that's what you meant moments after I posted.

Arober,
I looked into that a little earlier today. I don't fully understand that connection between sock layers & localhost/127.0.0.1 on a mac ... However, I read your history & have become a follower.

Thank you everyone for all your help. I have a project to wrap up by friday - I'll be able to make that deadline now.
I remember 'localhost' stopped working for me at one time.  I thought it was because I changed the IP and name of the machine.  But sometime later I checked and it was back doing what I expected.  I have Mac and Windows customers and more and more changes on both systems require rebooting.  Re-starting servers often doesn't do the trick because something else didn't get restarted.  Often that can be the anti-virus because it sets up proxies to filter internet traffic.

Thanks for the points and have a good week.