MySQL Forums
Forum List  »  Install & Repo

*** Possible solution! - Re: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Posted by: Manuel Medina
Date: September 27, 2008 08:25PM

After 3 weeks searching for answers on this problem and trying every single provided solution, this morning I finally understood what my problem was and I was able to run mysql successfully.

I'm using Gentoo, MySQL version 5.0.54 installed via emerge, but anyway I hope this solution can be helpful to someone.

My problem was that I had not changed the hostname on my machine. The default hostname was localhost, and whenever I tried to configure the server with emerge --config or by using mysql_install_db, I wasn't successful; emerge doesn't show any error message about this, just keeps going and tells you everything's done but you keep getting this annoying error; mysql_install_db at least tells you the installation failed, but doesn't give you a clue about what went wrong.

The system databases (mysql and test) were created successfully, but after getting this error and starting with the --skip-grant-tables option I realized that the user table in mysql database was empty. Yes, the root user, didn't exist. I tried to create it manually and use flush privileges, but I just kept getting the error.

I had to check the mysql_install_db script and found the following lines:

----

fill_help_tables="$pkgdatadir/fill_help_tables.sql"
create_system_tables="$pkgdatadir/mysql_system_tables.sql"
fill_system_tables="$pkgdatadir/mysql_system_tables_data.sql"

...

if { echo "use mysql;"; cat $create_system_tables $fill_system_tables; } | eval "$filter_cmd_line" | $mysqld_install_cmd_line > /dev/null

...

else
echo "Installation of system tables failed!"
echo
echo "Examine the logs in $ldata for more information."

----

So the $create_system_tables was running ok, so the problem had to be $fill_system_tables. I restarted mysqld with the --skip-grant-options and issued the command

mysql mysql < mysql_system_tables_data.sql

It was here when it told me that there was a duplicated entry for "localhost".

I proceeded to delete the tables from /var/lib/mysql, setup the host name to something else, and restart the computer (because even when I had set /etc/hostname and changed /etc/hosts properly, the /sbin/hostname command kept returning 'localhost', and this is the command the mysql_install_db performs to get the host name). After rebooting I simply executed mysql_install_db and voil√°! Everything went smoothly. The root user was created correctly (without a password), so I could enter using mysql -u root, changed the password and even created a couple of users.

I know this might sound useless to some of you guys, but give it a try. Change your host name to anything but "localhost" and try again. This problem kept me busy for some weeks (of course, I had more things to do) and I was about to file a bug on this.

Hope this information is useful.



Edited 1 time(s). Last edit at 09/27/2008 08:26PM by Manuel Medina.

Options: ReplyQuote


Subject
Written By
Posted
June 27, 2009 08:29PM
December 16, 2007 02:18AM
*** Possible solution! - Re: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
September 27, 2008 08:25PM
December 27, 2007 02:08PM
January 16, 2011 06:51AM
August 27, 2009 12:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.