Forum Moderators: coopster

Message Too Old, No Replies

MySQL - trouble connecting to server

Access denied for user 'root'@'localhost'

         

Therese

12:17 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



Good day

I'm a newbie at PHP, and I'm hoping someone could point me in the right direction.

I'm having trouble connecting to MySQL, I'm using the following code:

$link = mysql_connect("localhost", "root") or die (mysql_error());

and getting this error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in C:\xampp\xampp\htdocs\moviesite\table1.php on line 2
Access denied for user 'root'@'localhost' (using password: NO)

I'm using XAMPP for Windows Version 1.5.5 on a PC with Windows XP service pack 2. Firewall is off. How can I fix my connection?

phpsir

1:15 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



You need mysql_connect("localhost","youraccount","yourpassword")

Therese

1:30 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



It fails with a password as well. I heard that with XAMPP a password is not required if you enter the user as "root".

If you use a password, how do you tell the server which password it should accept?

Angelis

1:35 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



Your best bet is to setup a user with all privileges.

Scally_Ally

1:39 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



You should be able to connect like that using no password.
try maybe

$link = mysql_connect("localhost", "root", "") or die (mysql_error());

If that dont work, the only other thing i can think of is that MySQL is not turned on in the XAmp control panel?

(but angelis is right, you should set up a user for that particular database with specific privalages)

Ally

[edited by: Scally_Ally at 1:40 pm (utc) on Mar. 20, 2007]

Therese

2:11 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



Thanks for the code Ally, but it doesn't seem to be working. Angelis, how do I set up a user? From what I've read, it seems that I need to use phpMyAdmin, but I don't have access! :P

Does WinMySQLadmin 1.4 play any kind of role in this?

Scally_Ally

3:18 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



go to the xamp control panel by typing in "localhost" into your browser.
The link to the phpmyadmin is on the left hand navigation.

Ally

[edited by: Scally_Ally at 3:18 pm (utc) on Mar. 20, 2007]

Therese

5:42 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



Thanks to everyone who tried to help, I made an incredibly stupid mistake!

The user was "root" after all, and I specified the password shortly after installation, when I saw that mysql was "UNSECURE". I missed this: "The MySQL admin user root has no longer no password".

I confused MySQL's user settings with the general admin settings, and I thought that since I'd specified a username and a password for XAMPP's general administration, that would apply for MySQL.

So, in the script, I first tried "xamppUsername" and "xampAndMysqlPassword", and then "root" with no password. *shakes head*

And I finally got in phpMyAdmin. What a relief!