How to recover mysql root password in MacOS

前端 未结 4 503
梦谈多话
梦谈多话 2020-12-22 10:55

I start my MAMP and try to connect to my MySQL server via localhost or 127.0.0.1, I tried all the possible password that I think it is correct, but

4条回答
  •  爱一瞬间的悲伤
    2020-12-22 11:49

    Please follow the steps in same sequence.

    Make sure, your MySQL server is down. Execute below command :

    mysql.server stop
    

    Then, start MySQL server in safe mode

    mysql.server start --skip-grant-tables --skip-networking
    

    Then, connect to MySQL using root user.

    mysql -u root
    

    Change the database from none to mysql

    MariaDB [(none)]> use mysql;
    Database changed
    

    Update both authentication_string and password column with same password as shown below (if you get column not found error then remove one )

    MariaDB [mysql]> update user set authentication_string=PASSWORD('password'), password=PASSWORD('password') where user='root';
    
    MariaDB [mysql]> FLUSH PRIVILEGES;
    MariaDB [mysql]> quit;
    

    Now, stop everything including MySQL server and MAMP application as well.

    And, search for config.inc.php file inside your MAMP folder (you could use command + space and search this file).

    You may not have privilege to change this file. After updating the privilege of the file you need to look for $cfg['Servers'][$i]['password'] and update the password value as shown below.

    $cfg['Servers'][$i]['password'] = 'password';
    

    Save this file and restart everything in normal mode. And try connecting root user with new password as shown below :

    mysql -uroot -ppassword
    

提交回复
热议问题