mysql fresh install asking for root password

Solution 1:

The problem was I didn't have a root user to reset the password of to fix do: Shell:

/opt/local/share/mysql5/mysql/mysql.server stop
/opt/local/share/mysql5/mysql/mysql.server start --skip-grant-tables

mysql:

user mysql;
insert into user (Host, User, Password) values ('localhost','root','');
update user set Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Create_user_priv='Y' where user='root';
exit;

shell:

/opt/local/share/mysql5/mysql/mysql.server stop
/opt/local/share/mysql5/mysql/mysql.server start
mysql -u root

mysql:

grant all privileges on *.* to 'root'@'localhost' with grant option;

More information here: http://helpfromfriend.com/database/mysql/how-to-recreate-root-account-in-mysql/

Solution 2:

From dev.mysql.com/doc/refman/5.1/en/default-privileges.html :

The mysql.user grant table defines the initial MySQL user accounts and their access privileges:

Some accounts have the user name root. These are superuser accounts that have all privileges and can do anything. The initial root account passwords are empty, so anyone can connect to the MySQL server as root without a password and be granted all privileges.

Instructions for resetting the root password can be found here.