Lost MySQL Admin Password

I lost mysql admin (root user) password. How do I reset a lost MySQL admin (root) password under UNIX or Linux or BSD operating systems?

Type the following commands. First, stop current MySQL database server:
/etc/init.d/mysql stop
OR
/etc/init.d/mysqld stop
OR
/usr/local/etc/rc.d/mysql-server stop

Now, start mysql server without password so that you can restart the password:
mysqld_safe --skip-grant-tables &
Login without a password, enter:
mysql -u root
Finally, setup a new MySQL root user password, enter::

USE mysql;
UPDATE USER SET password=PASSWORD("NEW-ROOT-PASSWORD") WHERE USER='root';
FLUSH privileges;
quit

Replace NEW-ROOT-PASSWORD with actual password you want to use. Restart running mysql server:
/etc/init.d/mysql restart
Test it:
mysql -u root -p


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • santosamaru Apr 13, 2010 @ 16:26

    sir would you help me sir , i have problem with using ubuntu
    its my brother 6years old have changing my user privileges and set its none , i also cant goes as a root ,(crying)ehm i dont know how to set it back also i cant us my password in terminal to sudo su , its wont work did you know how i can get its back without reinstalling ?
    please help me sir
    thanks

  • niro Jan 4, 2012 @ 10:53

    Thanks alot!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum