Jimmy
Jimmy

Reputation: 2915

Can't connect to database on localhost

Ok, I have a really stupid problem here, and I'm starting to get really upset.

Just a few minutes ago, I could run my website on localhost with no problems. It's running in apache2 on the same machine as mySQL (an Ubuntu box).

I changed PHP's timezone and file upload size limit, then restarted both apache and mysql.

Now when I try to run the site from apache on the server, it can no longer select the database. As far as I can tell, it doesn't have a problem actually connecting to mysql, but when I run mysql_selectdb, it doesn't work.

If I run this site from my laptop, connecting to it via my home network, it works flawlessly.

I'm really really frustrated right now because it was working just fine minutes ago. I don't remember even changing any mySQL settings.

Can someone please help me figure out how this happened, and how to fix it? I really need to get this working as soon as possible.

EDIT: Here's the code I'm using to connect:

mysql_connect($serverUrl,'xx','xxx');
@mysql_selectdb('mydatabase') or die(mysql_error());

EDIT 2: When I use the root user login, it works just fine. To the best of my knowledge, I have given root access to the user I was using before, but I guess I could be wrong. Here is the command I was using in mySQL to give access:

GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost';

Upvotes: 1

Views: 4492

Answers (1)

Pekka
Pekka

Reputation: 449425

the user i'm using is definitely not 'www-data'.

My guess is you're using one of the mysql_* functions before you establish the connection. That will make the mySQL library use default login data - which, in your case, fail.

Check out the file name and line number of your error message to see where it gets triggered.

Upvotes: 1

Related Questions