I accidentally deleted my MySQL root user today on one of my dev servers. I thought I'd write a quickie about how I restored it.
The basic information I gathered from the MySQL manual, but of course I needed to restore the account, not just reset the password. It's a simple matter of replacing that init file with the proper SQL to create the user.
Plain TextCODE:
-
root# /etc/init.d/mysqld stop
-
root# su mysql
-
mysql$ pwd
-
/home/mysql
-
mysql$ echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'my_pass' WITH GRANT OPTION;"> mysql-init
-
mysql$ mysqld_safe --init-file=/home/mysql/mysql-init &
-
mysql$ rm mysql-init
-
mysql$ mysql -uroot -p # woot, works
(Note that it's important that you switch to the same user that MySQL uses when running mysqld_safe. This might be 'mysql' or something else, you'll need to check out your init files to see.)
October 20th, 2011 at 9:07 am
Thank you, these instructions worked great for me once I performed them as the mysql user as you say.
October 24th, 2011 at 7:12 pm
After much ado.. your instructions worked! Thanks!
December 6th, 2011 at 5:33 pm
Christopher you just saved my life. Thanks a lot!!
January 29th, 2012 at 6:05 pm
Hi Chris, quick question.. do i need to create a user mysql on my server? I don't think I have a user mysql on my server. Thanks!