Restoring deleted 'root' user and password for MySQL

前端 未结 9 1993
独厮守ぢ
独厮守ぢ 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 03:55

    using mamp. I made the apparently common mistake of deleting the root user when creating another user, I was locked out!

    so I found this post and tried to follow the directions but...

    I was getting this errores: -bash: mysql: command not found when trying to execute the command mysql commands and later I was getting this error DELETE command denied to user ''@'localhost' for table 'user' when tring to set properly privileges to the root user and do anything with that user once mysql in shell.

    so before I could use the commands eric and rolando posted (thank you guys for that) this is what I did

    I need to start mysqld properly so I had to do the following

    1. stop mysqld process found with

      ps aux | grep mysql

    and stop the mamp interface application aswell..

    1. and stopped any mysql process found with

      kill -9 [pid]

    do make sure no mysql process are running before you go any further.

    1. then I had to restart mysqld properly from the actual location where I had mysql binaries this commnad will start mysld without asking for a password (sort of like in safemode)

    /Applications/MAMP/Library/bin/mysqld --skip-grant-tables --skip-networking &

    I tried with my.cnf file but couldn't get it to work.

    1. then I had to go into mysql in shell

    /Applications/MAMP/Library/bin/mysql -u root -p

    (if prompted for a password just hit enter)

    1. then execute the commands eric and rolando posted, this time I didnt get any error "DELETE command denied to user ''@'localhost' for table 'user'" if you do, you didn't start mysqld properly

    2. then stop the mysqld service:

    /Applications/MAMP/Library/bin/mysqld stop

    then restarted mamp as usual with the gui

    and all started to work again as it was before... I was so relieved!!!

    2 hours of panic and trial and error with the console... valuable lessons learned..

    If I messed up any of the commands or the explanation (which could be the case as I was tracing my steps back as writing this post please let me know. I'd be happy to update the post.

    lastly don't give. it can be done!!

提交回复
热议问题