How to Reset the Root Password of MariaDB Database on Ubuntu
In this comprehensive guide, we will walk you through resetting the MariaDB root password on an Ubuntu server, ensuring your database remains secure and accessible.
Prerequisites
Before proceeding with the password reset, ensure you meet the following requirements:
- A server running Ubuntu (20.04, 22.04, or 24.04) with administrative access.
- MariaDB installed and running on your server.
- Basic familiarity with using the command line.
Main Steps to Reset the Root Password
Follow these steps to reset the root password of MariaDB:
Step 1: Stop the MariaDB Service
First, you need to stop the MariaDB service to make changes to its settings.
sudo systemctl stop mariadb
Step 2: Start MariaDB in Safe Mode
Next, start the MariaDB server in safe mode, which allows you to bypass the authentication system.
sudo mysqld_safe --skip-grant-tables &
Step 3: Log in to MariaDB
Now, log in to the MariaDB shell as the root user without a password.
mysql -u root
Step 4: Reset the Root Password
Once you are in the MariaDB shell, execute the following command to reset the root password:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Replace new_password with your desired password.
Step 5: Exit the MariaDB Shell
After resetting the password, exit the MariaDB shell.
EXIT;
Step 6: Stop Safe Mode and Restart MariaDB
Now, stop the MariaDB safe mode process and start the service normally.
sudo systemctl stop mariadb
sudo systemctl start mariadb
Step 7: Test the New Password
Finally, test the new root password by logging in to MariaDB.
mysql -u root -p
Enter the new password when prompted.
Advanced Configuration
After resetting the root password, consider the following configurations for enhanced security:
- Disable remote root login to prevent unauthorized access.
- Regularly update your MariaDB server to the latest version for security patches.
- Implement strong password policies for database users.
- Regularly back up your databases to prevent data loss.
Best Practices
Here are some best practices for managing your MariaDB database:
- Always run
mysql_secure_installationafter installation. - Create separate users with minimum privileges necessary for applications.
- Monitor your MariaDB logs for unusual activity.
- Consider using a firewall to restrict access to the database server.
Troubleshooting
If you encounter issues during the password reset process, consider the following tips:
- Ensure you have stopped the MariaDB service before starting in safe mode.
- If you cannot access the MariaDB shell, check the service status using
sudo systemctl status mariadb. - Verify that you have the correct version of MariaDB installed by running
mysql -V.
Conclusion
Resetting the root password for MariaDB on Ubuntu is a straightforward process that can enhance the security of your database. By following the steps and best practices outlined in this guide, you can ensure that your database remains secure and functional.
Always keep your database updated and monitor access logs to prevent unauthorized access.
Verifikasi Teknis
Panduan ini disusun berdasarkan referensi teknis terbaru. Namun, konfigurasi server dapat bervariasi. Lihat sumber referensi asli →
📚 Artikel Terkait
Cara Backup MySQL/MariaDB Secara Otomatis di Linux
510 kata • Baca selengkapnya →

Cara Memisahkan Apache Web Server dan MariaDB Database Server
712 kata • Baca selengkapnya →
Cara Migrasi dari MySQL 5.7 ke MariaDB 10.5 di Ubuntu 18.04
591 kata • Baca selengkapnya →
Cara Replikasi Database Master-Master MariaDB 10 di Ubuntu 16.04
528 kata • Baca selengkapnya →