Skip to content

Instantly share code, notes, and snippets.

@ebta
Created July 13, 2021 06:59
Show Gist options
  • Save ebta/f7bac49a631eb85bb8203581b2fed261 to your computer and use it in GitHub Desktop.
Save ebta/f7bac49a631eb85bb8203581b2fed261 to your computer and use it in GitHub Desktop.
Change mysql root password (MySQL 5.7)

Stop your databases

service mysqld stop

Modify /etc/my.cnf file add skip-grant-tables

sudo nano /etc/my.cnf

Add skip-grant-tables in [mysqld] section

[mysqld] 
skip-grant-tables

Start MySQL

service mysqld start

Select MySQL default database

mysql -u root
mysql> use mysql;
# Set a new password
mysql> update user set authentication_string=PASSWORD("yourpassword") where User='root';

Restart MySQL database

service mysqld restart
mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment