Skip to content

Instantly share code, notes, and snippets.

@duane
Last active December 15, 2015 22:28
Show Gist options
  • Save duane/5332758 to your computer and use it in GitHub Desktop.
Save duane/5332758 to your computer and use it in GitHub Desktop.
How to set root password for mysql

Note: the indented bits are intended to be copy/pasted. If you don't know your way around a unix system, and on top of that whatever weird design desisions ubuntu has implemented, it's very easy to mess them up.

Kill mysql and start it up in a completely unprivileged mode:

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

Now, mysqld_safe will block input, so you'll need to open a new terminal tab. Then, connect to mysql's meta database that includes auth information:

mysql -uroot mysql

Run these commands in the mysql prompt to set the root's password to 'password':

update user set Password=PASSWORD('password') where user='root';
flush privileges;
exit;

No, kill mysqld:

mysqladmin shutdown -uroot -ppassword

And restart it normally:

sudo /etc/init.d/mysql start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment