Skip to content

Instantly share code, notes, and snippets.

@zubaer-ahammed
Last active July 19, 2024 21:05
Show Gist options
  • Save zubaer-ahammed/c81c9a0e37adc1cb9a6cdc61c4190f52 to your computer and use it in GitHub Desktop.
Save zubaer-ahammed/c81c9a0e37adc1cb9a6cdc61c4190f52 to your computer and use it in GitHub Desktop.
Reset MySQL Root Password in Mac OS

Reset mysql root password in Mac OS:

First Stop MySQL:

  1. Go to: 'System Preferences' >> 'MySQL' and stop MySQL

OR,

  1. sudo /usr/local/mysql/support-files/mysql.server start
  2. sudo /usr/local/mysql/support-files/mysql.server stop
  3. sudo /usr/local/mysql/support-files/mysql.server status

Process to Reset MySQL Root Pass in Mac:

  1. Make sure you have Stopped MySQL first (above).

  2. Run the server in safe mode with privilege bypass: sudo mysqld_safe --skip-grant-tables

  3. In a new window connect to the database, set a new password and flush the permissions & quit: mysql -u root

  4. For MySQL older than MySQL 5.7 use:

    UPDATE mysql.user SET Password=PASSWORD('rootpass') WHERE User='root';

    For MySQL 5.7+ use:

    UPDATE mysql.user SET authentication_string=PASSWORD("rootpass") WHERE User='root';
  5. Now flush privileges:

    FLUSH PRIVILEGES;
  6. Restart MySQL server.

  7. More info: http://stackoverflow.com/questions/6474775/setting-the-mysql-root-user-password-on-os-x

@Victorcorcos
Copy link

Victorcorcos commented Jul 4, 2024

I’m having the same issue and the solution proposed didn’t work.

I’ve tried to change the password for the root user by executing sudo mysqld_safe --skip-grant-tables , then mysql -root, then the commands to reset the password, but it says that a mysqld process already exists, which blocks the execution of further commands.

$ sudo mysqld_safe --skip-grant-tables

2024-07-04T17:57:49.6NZ mysqld_safe Logging to '/opt/homebrew/var/mysql/Victors-MacBook-Pro.local.err'.
2024-07-04T17:57:49.6NZ mysqld_safe A mysqld process already exists

↳ This error is happening even after I kill all of the mysqld/mysql processes with sudo kill -9 or sudo pkill -9 mysqld or sudo killall -9 mysqld or sudo killall -9 mysqld_safe or listing all the processes with ps aux | grep mysql and killing each one of them manually via sudo kill -9 <process_id>.

I also tried to uninstall mysql, but when I run the the mysql_secure_installation command and try to setup a password, the following access denied error happens:

$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)

So, in the end, I can’t use MySQL at all on my machine due to this login issue. Could someone help me? Thank you!

@Bidyut7
Copy link

Bidyut7 commented Jul 10, 2024

sudo mysqld_safe --skip-grant-tables

after safe mode it is still showing the same error...what to do now??

@RavvyS
Copy link

RavvyS commented Jul 19, 2024

mysql -u root

"$ brew install mysql"
install and try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment