Solved

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

Posted on 2010-09-08
11
661 Views
Last Modified: 2012-05-10
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"
0
Comment
Question by:Imaginx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33628781
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.
0
 
LVL 26

Expert Comment

by:arober11
ID: 33629594
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/
0
 
LVL 1

Author Comment

by:Imaginx
ID: 33630021
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 ??
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 1

Author Comment

by:Imaginx
ID: 33630585
... Almost seems like apache is what won't connect ....

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

... just brainstorming.
0
 
LVL 4

Expert Comment

by:betopa
ID: 33630874
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.
0
 
LVL 1

Author Comment

by:Imaginx
ID: 33631077
I haven't upgraded the OS. And MySql has been working... How could it be an installation problem?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 33631295
'127.0.0.1' and 'localhost' are supposed to be the same thing... but both of the pages that I looked at said they aren't acting that way on both Mac and Windows these days.  Although Apache runs PHP, it doesn't directly run MySQL at all.  The pages I linked to have simple sample PHP programs for testing connectivity with MySQL.

On this page: http://dev.mysql.com/doc/refman/5.1/en/connecting.html  it talks about using '127.0.0.1' instead of 'localhost' on Unix systems and Mac OSX is a Unix derived system.

If MySQL has been working and it is not working now then Something has changed, apparently without you knowing about it.  Please try some of these things and let us know what happens.
0
 
LVL 4

Expert Comment

by:betopa
ID: 33631397
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.
0
 
LVL 26

Expert Comment

by:arober11
ID: 33632419
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.
0
 
LVL 1

Author Closing Comment

by:Imaginx
ID: 33632648
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33633008
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.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question