Restore mysql

From Hashmysql

Jump to: navigation, search

I've deleted the root user, and there's no other user with all privileges!

  • Stop mysqld and restart it with the --skip-grant-tables --user=root options (Windows users omit the --user=root portion).
  • Insert a record for the root user into the mysql.user table. The structure of the table changes with the version, so use the appropriate one:
    • For 5.1 and 5.2:
    • INSERT INTO `user` VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
    • For 5.0:
    • INSERT INTO `user` VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
    • For 4.1:
    • INSERT INTO `user` VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);
  • Stop mysqld and restart it as normal. You should now be able to login as root with a blank password.

I've dropped the entire mysql database, which holds all the privileges I need to login.

  • Stop mysqld and restart it with the --skip-grant-tables --user=root options (Windows users omit the --user=root portion).
  • Recreate the mysql database. If you have a backup, use that. Otherwise, issue CREATE DATABASE mysql; and then run the SQL file below that is appropriate for your version:
  • Stop mysqld and restart it as normal. You should now be able to login as root with a blank password.
Personal tools