PhD Social Science News : IN DATABASE and THEIR KIND … . HOW TO RESET LOST ROOT PASSWORD OF MARIADB OR MYSQL … .

To recover or reset your MariaDB root password, you must stop the database service, restart it without authentication checks, and apply a new password.

Before proceeding, try running sudo mysql -u root. In newer MariaDB versions, local root access often defaults to the unix_socket plugin, which allows you to log in automatically without a password if you use sudo.

If you still need to reset it, follow these step-by-step terminal instructions.

1. Stop the Database Service

Turn off the running MariaDB process to prevent resource conflicts.

  • Ubuntu / Debian:bashsudo systemctl stop mariadb Use code with caution.
  • CentOS / RHEL / Fedora:bashsudo systemctl stop mysqld Use code with caution.

2. Start MariaDB in Safe Mode

Launch the database by bypassing the privileges table (--skip-grant-tables) and disabling external network connections (--skip-networking) for security.

bash

sudo mysqld_safe --skip-grant-tables --skip-networking &

Use code with caution.

Note: The & symbol forces the command to run in the background, freeing up your terminal window.

3. Log In Without a Password

Connect to the server using the database client wrapper.

bash

mariadb -u root

Use code with caution.

(On older setups, you can use mysql -u root instead).

4. Apply the New Password

Once you see the MariaDB [(none)]> prompt, reload the permissions framework and declare your new credentials.

sql

-- Reload grant tables to make user alterations possible
FLUSH PRIVILEGES;

-- Update the password for the root user
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewStrongPassword';

-- Save and exit
FLUSH PRIVILEGES;
EXIT;

Use code with caution.

Replace YourNewStrongPassword with your chosen security key.

5. Restore Normal Operations

Kill the active background safe-mode process and bring the standard service back online.

bash

# Stop the safe mode instance
sudo kill $(pgrep mysqld_safe)

# Restart the standard service
sudo systemctl start mariadb

Use code with caution.

6. Verify the Changes

Test your updated login configuration to verify successful restoration.

bash

mariadb -u root -p

Use code with caution.

Type your newly designated password when requested.

Leave a Reply

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