Updated : Aug 27, 2015 in Linux

Resetting MySQL passwords in Linux Debian/Ubuntu

In Linux Debian/Ubuntu an extra user debian-sys-maint which also has all the access rights is used for maintenance. It can also be used to reset users passwords especially the root password when lost. Here are some tips regarding resetting them.

Resetting the ‘root’ password
mysqladmin -u root -p password "MyNewPass"
OR
mysql -u debian-sys-maint -p
update mysql.user set Password=password('MyNewPass') where User='root';
flush privileges;
quit;

Resetting/creating the user and giving it all the access rights.
eg. debian-sys-maint
mysql -u root -p
create user 'debian-sys-maint'@'localhost' identified by 'UserPassword';
grant all privileges on *.* to 'debian-sys-maint'@'localhost'
flush privileges;
quit;

SETTING root password for the first time.
In the case where after the initial installation of MySQL/MariaDB the request for root password was not initiated, you can set the root password as shown above. BUT if that doesn’t work then we probably have a case of plugin incompatibility. In this case it is recommended to use the following commands:
Login as root without password in MySQL/MariaDB server using the client program (mysql) and use the following commands:

UPDATE mysql.user SET authentication_string = PASSWORD('NEWPASSWORD'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit;




									

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: