Skip to content

Instantly share code, notes, and snippets.

@fallwith
Created May 23, 2011 22:10
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save fallwith/987731 to your computer and use it in GitHub Desktop.
Save fallwith/987731 to your computer and use it in GitHub Desktop.
Reset MySQL root password (Homebrew)
$> launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
$> /usr/local/Cellar/mysql/5.5.9/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.5.9 --datadir=/usr/local/Cellar/mysql/5.5.9/data --plugin-dir=/usr/local/Cellar/mysql/5.5.9/lib/plugin --log-error=/usr/local/Cellar/mysql/5.5.9/data/errors.err --pid-file=/usr/local/Cellar/mysql/5.5.9/data/pidfile.pid --skip-grant-tables
$> mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('root_password') WHERE User='root';
mysql> FLUSH PRIVILEGES;
$> kill `cat /usr/local/Cellar/mysql/5.5.9/data/pidfile.pid`
$> ps auwx | grep mysql
$> launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
@pelmered
Copy link

pelmered commented Oct 10, 2020

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

this work perfectly for me

Thanks @imamalys! This was the only thing that worked for me!

@petrewoo
Copy link

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

this work perfectly for me

Thanks @imamalys! It is worked for me!

@tilkofjin
Copy link

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

this work perfectly for me

@imamalys! It worked, Thanks so much!

@kkasaei
Copy link

kkasaei commented Jul 29, 2021

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

this work perfectly for me

@imamalys! It works for me, Thanks

@Johnhughes814
Copy link

Johnhughes814 commented Jan 31, 2022

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

this work perfectly for me
@imamalys THANK YOU!!!

@rajeswarivmarimuthu
Copy link

Everytime I restart my system, I will have to re-do these steps to work with mysql! Is there a way I can make this a permanent change?

@vijit-chandhok
Copy link

brew services restart mysql

thanks for this. it worked for me

@SaimumIslam
Copy link

/opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql to run safe server

@brandondebison
Copy link

Everytime I restart my system, I will have to re-do these steps to work with mysql! Is there a way I can make this a permanent change?

@rajeswarivmarimuthu Did you ever figure out what is causing this? mine is doing the same thing

@AlMahfuzKhanD
Copy link

$ brew services stop mysql $ pkill mysqld $ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!! $ brew postinstall mysql $ brew services restart mysql $ mysql -uroot

this work perfectly for me @imamalys THANK YOU!!!

Not working form me in macOS Sonoma 14.1.1
Any other solution?

@itay-shoushan
Copy link

$ brew services stop mysql $ pkill mysqld $ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!! $ brew postinstall mysql $ brew services restart mysql $ mysql -uroot
this work perfectly for me @imamalys THANK YOU!!!

Not working form me in macOS Sonoma 14.1.1 Any other solution?

try this, It's works for me :)

https://aungzanbaw.medium.com/how-to-reset-root-user-password-in-mysql-8-0-a5c328d098a8

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