Can’t login to MySQL as root :(

I was having issues logging into MySQL as root the other day. It took a while to figure things out. Ultimately, I had to follow the steps on two separate posts: http://rimuhosting.com/howto/mysqlinstall.jsp and http://bugs.mysql.com/bug.php?id=22118.

Here are the steps I took:

  1. Stop MySQL: ```bash /etc/init.d/mysql sto

  2. Edit config: ```bash
sudo vim /etc/my.cn
  1. Add line to section [mysqld]: ``` skip-grant-table

  4. Start MySQL: ```bash
/etc/init.d/mysql star
  1. Reset Root Password: ```bash mysql -e "update user set password = old_password(‘newpassword’) where user = ‘root’" mysq

  6. Kill MySQL: ```bash
kill `cat /var/run/mysqld/mysqld.pid
  1. Create an init-file: ```bash cat ~/mysql-init«EOF UPDATE mysql.user SET Grant_priv='Y’, Super_priv='Y’ WHERE User='root’; FLUSH PRIVILEGES; GRANT ALL ON . TO ‘root’@‘localhost’; EOF

  8. Run MySQL with the init file: ```bash
mysqld_safe --init-file=~/mysql-init &amp
  1. Remove the mysql-init file: ```bash rm ~/mysql-ini

 10. Restart MySQL: ```bash
/etc/init.d/mysql restar
  1. Login as root!

Part of this was also taken from the MySQL documentation for resetting a password, however, the contents of the file were changed to match one of the previously mentioned posts. If these steps don’t work, please visit the official documentation and give it a try again.

**IMPORTANT**

When you’re done following the above steps, please remove ‘skip-grant-tables’ from my.cnf. Thanks, Ian, for bringing this missed step to my attention!

Related Articles