MariaDB Reset Root Password

In this MariaDB tutorial, we will learn about the MariaDB reset root password and cover the following topics.

  • MariaDB reset root password windows
  • MariaDB reset root password ubuntu
  • MariaDB reset root password mac
  • MariaDB reset root password docker
  • MariaDB reset root password Linux
  • MariaDB reset root password xampp
  • MariaDB reset root password Debian 9
  • MariaDB 10.3 reset root password

MariaDB Reset Root Password Windows

In this section, we will learn how to reset the password of MariaDB. Sometimes, we forget the password, so will recover the password of MariaDB that running on a Windows machine. To recover the password we must have access to that MariaDB server.

Follow the below steps to reset the password.

Firstly, check the version of the MariaDB server by opening the command line on windows and typing the below command in that command line.

mysql --version
MariaDB reset root password windows checking version
MariaDB reset root password windows checking version

If unable to run this command in the command line, then go to the C:\Program Files\MariaDB 10.6 folder of MariaDB where it is installed on your windows machine and from the folder we can see it is MariaDB 10.6 version.

Secondly, stop the database server by opening the command line as the administrator, typing the below code.

net stop MairaDB

If the MariaDB version is 10.4 or a later version then run the above code, for the MariaDB version before 10.4 run the below code to stop the database server.

net stop MySQL

Here we are using the MariaDB 10.6 version so we will run the command net stop MariaDB.

MariaDB reset root password windows stop server
MariaDB reset root password windows stop server

Thirdly, restart the MariaDB server without loading the grant tables like user and db, these grant tables contain information about the user privileges that who can log in and has access to which database.

When the MariaDB server restarts without user privileges information or grant tables, then any user can log in to MariaDB using the command line without a password as the root user. Additionally, we will also skip the network while restarting MariaDB so that other users can’t connect to this server.

Go to the bin folder of MariaDB (C:\Program Files\MariaDB 10.6\bin) where it is installed. open the command line and type the below code to restart the MariaDB server without grant tables.

cd C:\Program Files\MariaDB 10.6\bin

./mysqld --skip-grant-tables --skip-networking --shared-memory
MariaDB reset root password windows restart server with grant tables
MariaDB reset root password windows restart server with grant tables

Fourthly, let’s reset the password of MariaDB, open the command line, and type the below code to log in as a root user without a password.

mysql -u root

After running the above code in the command line, we have logged into MariaDB as a root user that we can see in the below output.

MariaDB reset root password windows log in
MariaDB reset root password windows log in

Before resetting the password, load the grant tables that contain information about user privileges. Run the below code to reload the grant tables in MariaDB prompt.

FLUSH PRIVILEGES;

Reset the password using the below code.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_user_password';

If the MariaDB version is 10.1.20 or later then use the above code, otherwise use the below code for MariaDB version 10.1.20.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_user_password');

Again reload the grant tables using the below code.

FLUSH PRIVILEGES;

After running the above code, it shows the output as Query OK, 0 rows affected (0.011 sec).

Exit from the MariaDB prompt or session.

exit
MariaDB reset root password windows
MariaDB reset root password windows

We have reset the password of MariaDB manually. Now restart the MariaDB server normally by opening the command line as administrator and typing the below code in that command line.

net start MariaDB
MariaDB reset root password windows tutorial
MariaDB reset root password windows tutorial

Login with a new password in MariaDB by typing the below command in the command line.

mysql -u root -p

If the above command asks for a password then enter the new password that we reset for the root user in the above steps.

MariaDB reset root password windows reset login
MariaDB reset root password windows reset login

From the output, we can see that we have successfully reset the password of MariaDB.

Also, check: MariaDB Backup Database

MariaDB Reset Root Password Ubuntu

To reset the password of MariaDB on Ubuntu some of the commands are the same for MariaDB that we have used in the above sub-section. Follow the below steps to reset the password of MariaDB on Ubuntu.

First, check the version of MariaDB using by opening the terminal and typing the below code in that terminal.

mysql --version
MariaDB reset root password Ubuntu check version
MariaDB reset root password Ubuntu check version

Stop the MariaDB server, so we can reset the password of MariaDB manually. Use the below code to stop the database server.

sudo systemctl stop mariadb

After stopping the MariaDB server, run the below code to restart the MariaDB server without grant tables. When the MariaDB server restarts without user privileges information or grant tables, then any user can log in to MariaDB using the command line without a password as the root user.

Additionally, we will also skip the network while restarting MariaDB so that other users can’t connect to this server.

sudo mysqld_safe --skip-grant-tables --skip-networking &
MariaDB reset root password Ubuntu check restart without grant tables
MariaDB reset root password Ubuntu check restart without grant tables

Login into the MariaDB prompt without entering the password by typing the below code in the same terminal.

mysql -u root

Now we can reset the password of MariaDB because we logged in as a root user so we have full access to the database.

Before resetting the password, reload the grant table using the below code.

FLUSH PRIVILEGES;

Reset the password using the below code.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_user_password';

If the MariaDB version is 10.1.20 or later then use the above code, otherwise use the below code for MariaDB version 10.1.20.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_user_password');

Again reload the grant tables using the below code.

FLUSH PRIVILEGES;

After running the above code, it shows the output as Query OK, 0 rows affected (0.001 sec).

Exit from the MariaDB prompt or session.

exit
MariaDB reset root password Ubuntu
MariaDB reset root password Ubuntu

We have reset the password of the MariaDB server manually, After this, restart the MariaDB server in normal mode by restarting the Ubuntu machine. Run the below code to check the status of the MariaDB server.

systemctl status mariadb

Then login into the MariaDB server with a new password.

mysql -u root -p
MariaDB reset root password Ubuntu login
MariaDB reset root password Ubuntu login

From the output, we can see that we have successfully login into MariaDB with a new password.

Read: MariaDB Enable Remote Access

MariaDB Reset Root Password Mac

To reset the root password in Mac OS, follow the steps provided in the above subsection “MariaDB reset root password Ubuntu”.

MariaDB Reset Root Password Docker

To reset the root password of MariaDB follow the below steps.

Open the docker-compose file for MariaDB and add the line command: --skip-grant-tables at the end of the file as given in the below output.

# Use root/example as user/password credentials
version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    ports:
      - 8080:8080
    command: --skip-grant-tables
MariaDB reset root password docker compose file
MariaDB reset root password docker-compose file

After adding the line, restart the container MariaDB using the below code in the directory where the above compose file exists.

docker-compose down -- to stop the running container

Then start the container.

docker-compose up -- to start the container with new setting 

Access the bash shell of the MariaDB container by clicking on the button CLI in docker application.

Login into MariaDB as root user using the below code.

mysql -u root

Before resetting the password, reload the grant table using the below code.

FLUSH PRIVILEGES;

Reset the password using the below code.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_user_password';

If the MariaDB version is 10.1.20 or later then use the above code, otherwise use the below code for MariaDB version 10.1.20.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_user_password');

Again reload the grant tables using the below code.

FLUSH PRIVILEGES;

After running the above code, it shows the output as Query OK, 0 rows affected (0.011 sec).

Exit from the MariaDB prompt or session.

exit
MariaDB reset root password docker
MariaDB reset root password docker

After performing the above steps, exit the bash shell of the MariaDB container, stop the MariaDB container and open the docker-compose file, remove the line command: --skip-grant-tables from the file and save the file. Then restart the container again with changes setting using the below code.

sudo nano docker-compose file -- opening the compose file

Then start the container.

docker-compose up -- to start the container with new setting 

Again access the bash shell of the MariaDB container using the below code or use the docker desktop application to open the base shell of that container.

docker exec -it mariadbtips-db-1 bash

Login into MariaDB as root user with a new password using the below code.

mysql -u root -p
MariaDB reset root password docker login
MariaDB reset root password docker login

Read: MariaDB Check If Rows Exists

MariaDB Reset Root Password Linux

To reset the root password of MariaDB in Linux, follow the steps of the tutorial “MariaDB reset root password Ubuntu” because all Linux-based operating systems follow the same steps to reset the password of MariaDB.

MariaDB Reset Root Password xampp

The XAMPP is a cross-platform web server developed by Apache. So here we will reset the password of MariaDB using XAMPP shell and for that follow the below steps.

Open the XAMPP control panel on your system and click on the button Conifg of MySQL, then option appears as my.ini and click on my.ini option to open the file as shown in the below picture.

MariaDB reset root password xampp control panel
MariaDB reset root password xampp control panel

After opening the file, add the given line below the line [mysqld] of file my.ini and save the file.

skip-grant-tables
MariaDB reset root password xampp configuration
MariaDB reset root password xampp configuration

Then come back to the XAMPP control panel, stop and start the MySQL server to take effect on changes that we made. After this, we will be able to log into the database without a password as the root user.

Click on the button Shell to open the shell, check the version, and login into the database without a password.

MariaDB reset root password xampp configuration login
MariaDB reset root password xampp configuration login

Before resetting the password, reload the grant table using the below code.

FLUSH PRIVILEGES;

Reset the password using the below code.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_user_password';

If the MariaDB version is 10.1.20 or later then use the above code, otherwise use the below code for MariaDB version 10.1.20.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_user_password');

Again reload the grant tables using the below code.

FLUSH PRIVILEGES;

After running the above code, it shows the output as Query OK, 0 rows affected (0.000 sec).

Exit from the MariaDB prompt or session.

exit
MariaDB reset root password xampp
MariaDB reset root password xampp

Then again open the file my.ini and remove the line skip-grant-tables and restart the MySQL server.

Login with a new password that we set for the root user in the above steps.

mysql -u root -p
MariaDB reset root password xampp login after reset
MariaDB reset root password xampp login after reset

Now we have successfully logged into the database with a reset password.

Read: MariaDB Truncate Table + Examples

MariaDB reset root password Debian 9

The same steps are used to reset the password of MariaDB in Debian 9 as we have used the above sub-section “MariaDB reset root password Ubuntu”.

Read: MariaDB Rename View

MariaDB 10.3 Reset Root Password

So in this section, we will reset the root password of MariaDB 10.3 and follow the below steps.

Firstly, check the version of the MariaDB server by opening the command line on windows and typing the below command in that command line.

mysql --version
MariaDB reset root password windows checking version MariaDB 10.3
MariaDB reset root password windows checking version MariaDB 10.3

If unable to run this command in the command line, then go to the C:\Program Files\MariaDB 10.3 folder of MariaDB where it is installed on your windows machine and from the folder we can see it is MariaDB 10.3 version.

Secondly, stop the database server by opening the command line as the administrator, typing the below code.

net stop MairaDB

If the MariaDB version is 10.4 or a later version then run the above code, for the MariaDB version before 10.4 run the below code to stop the database server.

net stop MySQL

Here we are using the MariaDB 10.6 version so we will run the command net stop MariaDB.

MariaDB reset root password windows stop server
MariaDB reset root password windows stop server

Thirdly, restart the MariaDB server without loading the grant tables like user and db, these grant tables contain information about the user privileges that who can log in and has access to which database.

When the MariaDB server restarts without user privileges information or grant tables, then any user can log in to MariaDB using the command line without a password as the root user. Additionally, we will also skip the network while restarting MariaDB so that other users can’t connect to this server.

Go to the bin folder of MariaDB (C:\Program Files\MariaDB 10.6\bin) where it is installed. open the command line and type the below code to restart the MariaDB server without grant tables.

cd C:\Program Files\MariaDB 10.6\bin

./mysqld --skip-grant-tables --skip-networking --shared-memory
MariaDB reset root password windows restart server with grant tables
MariaDB reset root password windows restart server with grant tables

Fourthly, let’s reset the password of MariaDB, open the command line, and type the below code to log in as a root user without a password.

mysql -u root

After running the above code in the command line, we have logged into MariaDB as a root user that we can see in the below output.

MariaDB reset root password windows log in
MariaDB reset root password windows log in

Before resetting the password, load the grant tables that contain information about user privileges. Run the below code to reload the grant tables in MariaDB prompt.

FLUSH PRIVILEGES;

Reset the password using the below code.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_user_password';

If the MariaDB version is 10.1.20 or later then use the above code, otherwise use the below code for MariaDB version 10.1.20.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_user_password');

Again reload the grant tables using the below code.

FLUSH PRIVILEGES;

After running the above code, it shows the output as Query OK, 0 rows affected (0.011 sec).

Exit from the MariaDB prompt or session.

exit
MariaDB reset root password windows
MariaDB reset root password windows

We have reset the password of MariaDB manually. Now restart the MariaDB server normally by opening the command line as administrator and typing the below code in that command line.

net start MariaDB
MariaDB reset root password windows tutorial
MariaDB reset root password windows tutorial

Login with a new password in MariaDB by typing the below command in the command line.

mysql -u root -p

If the above command asks for a password then enter the new password that we reset for the root user in the above steps.

MariaDB reset root password windows reset login
MariaDB reset root password windows reset login

From the output, we can see that we have successfully reset the password of MariaDB.

You may also like to read the following MariaDB tutorials.

So, in this tutorial, we have learned about the “MariaDB reset root password“, learned how to reset the MariaDB on different systems, and covered the following topics.

  • MariaDB reset root password windows
  • MariaDB reset root password ubuntu
  • MariaDB reset root password mac
  • MariaDB reset root password docker
  • MariaDB reset root password Linux
  • MariaDB reset root password xampp
  • MariaDB reset root password Debian 9
  • MariaDB 10.3 reset root password