(Easy Way)How to reset MySQL or MariaDB root password on ubuntu.

How to reset MySQL or MariaDB root password on ubuntu Linux



The MySQL root password allow the root user to have full access to the MySQL database and users.
reset, Set or change he MySQL root password on Ubuntu. Use the following lines in your terminal.

Enter in root mode
sudo -i

First check mysql version and note it.
# mysql --version

Stop the MySQL service.
# service mysql stop

Start MySQL without password and permission checks.
# sudo mysqld_safe --skip-grant-tables --skip-networking &
 *Press [ENTER] again if your output is halted.

Connect to MySQL
# mysql -u root
Press enter

Run database server to reload the grant tables
FLUSH PRIVILEGES;

Now we can actually change the root password.

For MySQL 5.7.6 and newer as well as MariaDB 10.1.20 and newer, use the following command.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

For MySQL 5.7.5 and older as well as MariaDB 10.1.20 and older, use:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');

exit

Restart the Database Server Normally
For MySQL, use:
# sudo kill `cat /var/run/mysqld/mysqld.pid`
press enter

For MariaDB, use:
# sudo kill `/var/run/mariadb/mariadb.pid`
press enter

For MySQL, use:
# service mysql start

For MariaDB, use:
# service mariadb start

Now you can confirm that the new password has been applied correctly by running:

# mysql -u root -p



SHARE

Ibrar Ansari

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment