Press ESC to close

Resetting Your MySQL or MariaDB Root Password on Ubuntu

İçindekiler

Losing or forgetting the root password for MySQL or MariaDB servers while working on the Ubuntu operating system is a common issue. This situation can be a serious problem for server administrators because root access is essential for database management. Fortunately, there are several steps and strategies to resolve this issue. In this article, I will provide a detailed guide on how to reset the root password for MySQL or MariaDB servers on Ubuntu.

Application

1. Connecting to the Server via SSH:

The first step is to connect to the server via SSH (Secure Shell). Use an SSH client to connect to the server and log in with the root username and password.
				
					ssh [username]@[host_ip_address]
				
			

2. Stopping the MySQL or MariaDB Service:

Before starting the password reset process, you need to stop the MySQL or MariaDB service. This allows you to make secure changes to the database system.

For MySQL:

				
					sudo systemctl stop mysql
				
			

For MariaDB:

				
					sudo systemctl stop mariadb
				
			

3. Starting MySQL or MariaDB in Safe Mode:

Next, you need to start the MySQL or MariaDB service in safe mode. This mode provides the necessary permissions for the password reset process.
				
					sudo mysqld_safe --skip-grant-tables &
				
			

4. Connecting to the MySQL or MariaDB Server:

After starting the service in safe mode, you need to reconnect to the MySQL or MariaDB server.
				
					mysql -u root
				
			

5. Resetting the Password:

Once successfully connected to the MySQL or MariaDB server, you can reset the root password. Use the following SQL query to assign a new password:
				
					UPDATE mysql.user SET authentication_string = PASSWORD('yeni_şifre') WHERE User = 'root';

				
			

6. Confirming Changes and Exiting:

After successfully assigning the new password, confirm the changes and exit the server:
				
					FLUSH PRIVILEGES;
EXIT;
				
			

7. Starting the Service in Normal Mode:

Now that the password has been reset, you can start the MySQL or MariaDB service in normal mode.

For MySQL:

				
					sudo systemctl start mysql
				
			

For MariaDB:

				
					sudo systemctl start mariadb
				
			

Conclusion

By following these steps, you can successfully reset the root password for both MySQL and MariaDB.

Leave a Reply

Your email address will not be published. Required fields are marked *