ANS Documentation

Improve This Doc
  • Cloud
  • Domains and DNS management
  • Backup and High Availability
  • eCommerce Stacks
  • Security
  • Email
  • Monitoring and usage management
  • Networking
  • Operating systems
    • Linux
      • Basics
      • Apache
      • Control Panels
      • FTP
      • Magento
      • Miscellaneous
      • MySQL
      • NGINX
      • PHP
      • PHP-FPM
      • Setting up Websites
      • NFS
      • VPN
      • Percona
      • SSH
      • SSL
      • Git
      • Redis
      • Elasticsearch
      • MongoDB
      • Ncdu
    • VMware ESXi
    • Windows
  • Webcelerator
  • MyUKFast
  • Home >
  • Operating systems >
  • Linux >
  • MySQL >
  • Reset MySQL Root Password

Reset MySQL Root Password¶

Skip the grants table¶

The first step to resetting a lost MySQL root password, is to restart your MySQL server with this variable set:

  • skip-grant-tables

You can do this, by editing the MySQL configuration file usually found here:

vim /etc/my.cnf

As per the below, add skip-grant-tables to your MySQL config:

[mysqld]
skip-grant-tables

Now that this has been set, you can restart MySQL:

systemctl restart mysql

And try connecting

mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.18-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Updating The Password¶

Now that MySQL is running with skip-grant-tables, you can update the password with this command:

UPDATE mysql.user SET Password=PASSWORD('password_here') WHERE User='root';
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('password_here') WHERE User='root';
Query OK, 4 rows affected (0.002 sec)
Rows matched: 4  Changed: 4  Warnings: 0

Now run FLUSH PRIVILEGES; to write the changes to disk:

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.003 sec)

You can now remove the skip-grant-tables flag from /etc/my.cnf, and restart MySQL:

systemctl restart mysql

Next Article > MySQL Remote Access

  • Useful Links
  • SMB
  • Enterprise
  • Channel
  • Public Sector
  • ANS Data Centres
  • About ANS
  • Careers
  • Blog
  • Get in touch
  •  
  • Sales 0800 458 4545
  • Support 0800 230 0032
  • Get in touch

© ANS Group Limited | Terms and Conditions | Corporate Guidance | Sitemap
ANS Group Limited, registered in England and Wales, company registration number 03176761, registered office 1 Archway, Birley Fields, Manchester M15 5QJ