Mysql – thesql fresh install asking for root password

installationMySQLroot

A couple of years back i tried to install apache, php and mysql on my mac. I got it all working but in the end i got fed up of doing everything on the command line so switched to mamp

Now I'm fed up with the sluggishness of mamp and want to get better at using the command line. I'm trying to set it up my self (well, with mac ports) but i forgot the password for the mysql root user. No big problem, no data on there I need, I'll just reinstall.

I uninstall of mysql, re-installed mysql and ran:

sudo -u _mysql mysql_install_db5 /opt/local/share/mysql5/mysql/mysql.server start

All worked fine but doing mysqladmin5 -u root -p ping asks me for a password and mysqladmin5 -u root ping doesn't work.

Best Answer

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/