Skip to content

Instantly share code, notes, and snippets.

@tian-im
Last active October 24, 2018 01:27
Show Gist options
  • Save tian-im/f8e9467923b3a31674cc5b7b4f455c1a to your computer and use it in GitHub Desktop.
Save tian-im/f8e9467923b3a31674cc5b7b4f455c1a to your computer and use it in GitHub Desktop.
Reset Mysql root password in Ubuntu
# 1. stop mysqld service
# after this command, remember to double check if /var/run/mysqld folder exists and its owner is mysql:mysql
sudo /etc/init.d/mysql stop

# might have to do this
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

# 2. start mysql without password
sudo mysqld_safe --skip-grant-tables &

# 3. enter mysql console
mysql -uroot
use mysql; # use mysql table
update user set authentication_string=PASSWORD("") where User='root'; # update password to nothing
update user set plugin="mysql_native_password" where User='root'; # set password resolving to default mechanism for root user

flush privileges;
quit;
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start # reset mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment