I. What is MySQL?

MySQL is the world’s most popular free and open-source database management system and is very popular with developers in application development. Because MySQL is a high-speed, stable and easy-to-use database management system that is portable, works on many operating systems, it provides a large system of very powerful utility functions. With high speed and security, MySQL is well suited for applications that access databases on the internet. Users can download MySQL for free from the homepage.

MySQL has many versions for different operating systems: Win32 version for Windows, Linux, Mac OS X, Unix, FreeBSD, NetBSD, Novell NetWare, SGI Irix, Solaris, SunOS, etc.

MySQL is one of the very basic examples of a Relational Database Management System using Structured Query Language (SQL).

MySQL is used to support Node.js, PHP, Perl, and many other languages, as a place to store information on web pages written in NodeJs, PHP or Perl, etc.

 

II. Reset MySQL Root Password on aaPanel

To reset the MySQL Root password on aaPanel, we can follow these 2 ways and 3 steps:

Step 1: SSH into your DirectAdmin system

To reset the MySQL Root password on aaPanel, we first need to SSH or access your VPS/server with root privileges. If you don’t know how to SSH into your VPS/Server, you can refer to the following tutorial:

After successfully SSH, we continue with step 2 to change the MySQL/MariaDB configuration at my.cnf file.

Step 2: Reset MySQL Root Password

 

  • Cách 1: Thực hiện bằng lệnh thông qua SSH


Chỉnh sửa cấu hình file my.cnf

Normally, the my.cnf configuration file will be located at /etc/my.cnf or /etc/mysql/my.cnf and on aaPanel the file will be at /etc/my.cnf.

To edit the configuration, we use the following command:

  
AZDIGI Tutorial
vi /etc/my.cnf
    

At the content of the configuration file, press i to edit and add the content below under the [mysqld] line as shown:

  
AZDIGI Tutorial
skip-grant-tables
    
Reset MySQL Root Password

After editing, you save and restart the Mysql service with the command:

  
AZDIGI Tutorial
systemctl restart mysql
    

Next, you perform Mysql password reset with the following commands:

  
AZDIGI Tutorial
mysql -u root -p   (Nhấn Enter để tiếp tục)
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';   (NewPassword là mật khẩu mới cần đổi)
quit;
    

Below is the result after I run the commands:

Reset MySQL Root Password

 

 

  • Cách 2: Thực thiện tại giao diện aaPanel

First, you need to log in to aaPanel and go to Databases => root password => enter the new root password => Submit.

Reset MySQL Root Password

So we have successfully changed the Mysql root password.

 

Step 3: Check the password after changing

To check, use the command below and enter a new password:

  
AZDIGI Tutorial
mysql -u root -p
    

If you can login as shown below, you have successfully changed your password.

Reset MySQL Root Password

 

III. Summary

Hopefully, this article will help you in some cases when you forget or need to recover the MySQL root password on aaPanel. If you find this helpful article, please share it widely.

https://azdigi.com/blog/en/webserver-panel-en/aapanel-en/reset-mysql-root-password-on-aapanel/