Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scalp42/2409614 to your computer and use it in GitHub Desktop.
Save scalp42/2409614 to your computer and use it in GitHub Desktop.
Reset MySQL root password (Homebrew)
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
mkdir -p /usr/local/Cellar/mysql/`brew info mysql | head -n 1 | awk '{print $3}'`/data/
/usr/local/Cellar/mysql/`brew info mysql | head -n 1 | awk '{print $3}'`/bin/mysqld --basedir=/usr/local/Cellar/mysql/`brew info mysql | head -n 1 | awk '{print $3}'` --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/`brew info mysql | head -n 1 | awk '{print $3}'`/lib/plugin --log-error=/usr/local/Cellar/mysql/`brew info mysql | head -n 1 | awk '{print $3}'`/data/errors.err --pid-file=/usr/local/Cellar/mysql/`brew info mysql | head -n 1 | awk '{print $3}'`/data/pidfile.pid --skip-grant-tables 2>&1 &
echo "UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;" > /tmp/resetroot.sql
mysql < /tmp/resetroot.sql
kill `cat /usr/local/Cellar/mysql/\`brew info mysql | head -n 1 | awk '{print $3}'\`/data/pidfile.pid`
rm -f /tmp/resetroot.sql
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment