Home > PHP and MySQL: Visual QuickPro Guide (2nd Ed.) > Topic

mysql_connect(): access denied for root@localhost

Posted by Jane 
This forum is now read only. You can not log in or make any changes. Please use the new forum linked above.
As of March 14, 2011, this forum has been replaced and is permanently set to read-only mode. This means you can view any existing post but cannot open new posts or reply to existing ones. The new forum is located athttp://www.larryullman.com/forums/If you need to post a message, you'll need to register there. If you have to post in order to follow up on a thread started here, well, that's going to be a bit of a pain. I would recommend just posting the appropriate information, or copying the original text from here, or linking to your thread here. I apologize for the inconvenience but this purge will make for better forums in the long run. Thanks.
mysql_connect(): access denied for root@localhost
July 21, 2006 08:25PM
I installed mysql 5.0.22, apache server 2.0.58, and php 5.1.4 on my window XP.

I also did the following:
libmysql.dll copy from e:/php to C:/windows/system32 foler.
In php.ini: for the line ;extension=php_mysql.dll, I removed the ; to activate it.
Make the change so that: extension_dir = "e:\php\ext"
Also, change e:\php\php.init-dist to e:/php.ini

All my PHP scripts were run with no problem until I include the mysql database connection. When I use the function mysql_connect("localhost", "root", "password"); error appears as follows:

mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in E:\Documents and Settings\My Documents\My Web Pages\testmysql.php on line 12

How to resolve this? Any Input is GREATLY appreaciated.
Re: mysql_connect(): access denied for root@localhost
July 22, 2006 02:15PM
That all sounds great and thanks for including all the details. Is the MySQL "root" user password simply "password"? How did you establish this password?

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: mysql_connect(): access denied for root@localhost
July 22, 2006 03:43PM
Thank you very much for your response, Larry. I assigned the "root" user password (with my own password, not just simply "password") during the Mysql configuration process.

In fact, when I removed the mysql 5.0 and reinstalled it, it appeared that
I could not pass the last step of MySQL server instance configuration -- Apply security settings. A "Connection Error" window was popped up which says:

"The security settings could not be applied to the database because the connection has failed with the following error:
Error Nr. 1045
Access denied for user 'root'@'localhost' [using password: YES]

If a personal firewall is running on your machine, please make sure you have opened the TCP port 3306 for connections. Otherwise no client application can connect to the server. After you have opened the port, please press [Retry] to apply the security settings.

If you are reinstalling after you just uninstalled the MySQL server please note that the data directory was not removed automatically. Therefore the old password from your last installation is still needed to connect to the server. In this case please select skip now and re-run the Configuration Wizard from the start menu."
Re: mysql_connect(): access denied for root@localhost
July 22, 2006 03:49PM
Okay, well, in your PHP connection script, did you use your actual password, not "password"? And can you connect to MySQL using the mysql monitor?

I'm not sure how reinstalling MySQL might play into this, or why you might have done that, but that may be the problem. You'll need to first confirm that you can connect to MySQL using the mysql monitor with the proper root/password combination.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: mysql_connect(): access denied for root@localhost
July 22, 2006 05:52PM
Thanks.

Yes. I use my actual password. I cannot connect to mysql with mysql monitor. The same error no. 1045 appeared.

Re: mysql_connect(): access denied for root@localhost
July 22, 2006 06:34PM
Okay, that would suggest that you do not have the right root user password. Did you change it during your multiple installs? Do you remember what the original root user password was? If not, you'll need to reset the root user password. There are instructions for doing so in the MySQL manual.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: mysql_connect(): access denied for root@localhost
October 20, 2007 04:25PM
Jane Wrote:
-------------------------------------------------------
> I installed mysql 5.0.22, apache server 2.0.58,
> and php 5.1.4 on my window XP.
>
> I also did the following:
> libmysql.dll copy from e:/php to
> C:/windows/system32 foler.
> In php.ini: for the line ;extension=php_mysql.dll,
> I removed the ; to activate it.
> Make the change so that: extension_dir =
> "e:\php\ext"
> Also, change e:\php\php.init-dist to e:/php.ini
>
> All my PHP scripts were run with no problem until
> I include the mysql database connection. When I
> use the function mysql_connect("localhost",
> "root", "password"); error appears as follows:
>
> mysql_connect() : Access denied for user
> 'root'@'localhost' (using password: YES) in
> E:\Documents and Settings\My Documents\My Web
> Pages\testmysql.php on line 12
>
> How to resolve this? Any Input is GREATLY
> appreaciated.
>

Thanks for the tutorial. It worked.

Yours truly...
Ghost