Restoring deleted 'root' user and password for MySQL

前端 未结 9 1939
独厮守ぢ
独厮守ぢ 2020-11-27 03:47

I accidentally deleted the root user on my local dev setup of MAMP/MySQL running on OS X. There are no other users created to get back into MySQL.

Thi

相关标签:
9条回答
  • 2020-11-27 04:02

    Just wanted to contribute how I resolved this. If you accidentally deleted the root user in MAMP PRO and are using OSX with Time Machine backups. Simply go to this folder in finder:

    /Library/Application Support/appsolute/

    Then 'Enter Time Machine' from the top menu bar and restore a recent backup of the MAMP PRO folder. Saved a lot of hassle for me.

    0 讨论(0)
  • 2020-11-27 04:08

    I have a quick and dirty way

    Get someone with SysAdmin rights and do the following:

    1. Add 'skip-grant-tables' to my.cnf under the [mysqld] section

    2. restart mysql

    3. type mysql with no password and hit enter

    4. Run This:

      DELETE FROM mysql.user 
      WHERE  user = 'root' 
             AND host = 'localhost'; 
      
      INSERT INTO mysql.user 
      SET user = 'root', 
          host = 'localhost', 
          password = Password('whatevernewpassword'), 
          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',
          Event_priv = 'y',
          Trigger_priv = 'y',
          Create_tablespace_priv = 'y';
      
    5. exit from mysql

    6. remove 'skip-grant-tables' from my.cnf under the [mysqld] section

    7. restart mysql

    That should be all!

    0 讨论(0)
  • 2020-11-27 04:12

    I did exactly the same thing yesterday, being new to macs and the sql server. I accidentally deleted the root user because I pressed the wrong button in Privileges whilst trying to set up a new user and password.

    I did not have any work of any use on this computer so was not worried about deleting my websites.

    • I first uninstalled MAMP Pro (for which I had an icon in Launchpad).
    • I then deleted MAMP directory from the Applications folder.
    • I then reinstalled MAMP from the internet download.
    • I then DELETED all my cookies, cache etc from safari.
    • I shut down my computer and rebooted.

    I now have access to phpMyAdmin through the link on the startup page once MAMP is booted.

    0 讨论(0)
提交回复
热议问题