How To Reset Your MySQL or MariaDB Root Password

How To Reset Your MySQL or MariaDB Root Password

How To Reset Your MySQL or MariaDB Root Password

If you have forgotten your MySQL or MariaDB root password, don't worry. You can easily reset it by following these simple steps:

  1. Stop the MySQL or MariaDB service
  2. Start the MySQL or MariaDB service with the --skip-grant-tables option
  3. Connect to the MySQL or MariaDB server using the mysql command
  4. Change the root password using the UPDATE statement
  5. Restart the MySQL or MariaDB service

Let's go through each step in more detail.

Step 1: Stop the MySQL or MariaDB service

On Ubuntu or Debian, run the following command:

sudo systemctl stop mysql

On CentOS or Fedora, run the following command:

sudo systemctl stop mariadb

Step 2: Start the MySQL or MariaDB service with the --skip-grant-tables option

Run the following command to start the service with the --skip-grant-tables option:

sudo mysqld_safe --skip-grant-tables &

This will start the MySQL or MariaDB service with no password authentication, allowing you to reset the root password.

Step 3: Connect to the MySQL or MariaDB server using the mysql command

Open a new terminal window and run the following command:

mysql -u root

This will connect you to the MySQL or MariaDB server as the root user.

Step 4: Change the root password using the UPDATE statement

Run the following command to update the root password:

UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';

Replace 'new_password' with your desired password.

Step 5: Restart the MySQL or MariaDB service

Stop the running MySQL or MariaDB service and start it normally:

On Ubuntu or Debian, run the following commands:

sudo systemctl stop mysql sudo systemctl start mysql

On CentOS or Fedora, run the following commands:

sudo systemctl stop mariadb sudo systemctl start mariadb

That's it! You should now be able to login to your MySQL or MariaDB server with the new root password.

Keywords: MySQL, MariaDB, root password, reset password, tutorial, step-by-step, authentication, UPDATE statement, systemctl, mysqld_safe, new password.

Комментарии

Популярные сообщения из этого блога

How To Modify CSS Classes in JavaScript

How To Backup MySQL Databases on an Ubuntu VPS

How To Backup PostgreSQL Databases on an Ubuntu VPS