Both MySQL and MariaDB are the most popular open source database systems meant for Linux based operating systems.

We sometimes come across situation, where we forget the root or other MySQL users password. You have forgotten the MySQL root or want to just change the other users’ passwords then following commands will help you to reset it

The process given below is quite simple and work almost on all Linux operating systems such as Ubuntu, Debian, Centos and more.

Note: The MySQL default root password is empty that means there is no password assigned to when you installed the MySQL or MariaDB freshly. You just need to press enter after giving the username i.e root.

         A.   Mysql command to reset root user password

1.     Go to the terminal CLI of your Linux system and type the below commands:

sudo mysql -uroot

 

root user

 

2.     Once it connected with the MySQL server then select the MYSQL database.

use mysql;

3.     Use the below command to change the MySQL root user password. 

update user set password=PASSWORD("mynewpassword") where User='root';

flush privileges;

quit

 

use mysql

 

4.     Restart the mysql service

systemctl restart mysql

 

B.   Mysql command to change a user password

You can find out all MySQL Database users just by using command mentioned below, from here you can select the user of which password needs to be reset:

SELECT User FROM mysql.user;

 

1. Open the command terminal and connect to the MySQL user and enter the MySQL root user password to log in.

sudo mysql -u root  -p

 

2. Switch to MySQL database

use mysql;

 

3. Command to change the USER password in MySQL database server version 5.7.5 or older versions.

SET PASSWORD FOR 'user-name-here'@'localhost' = PASSWORD('new-password');

 

C.    To change the MySQL user password in the latest version of the MySQL database server 5.7.6 or above.

ALTER USER 'user-name-here'@'localhost' IDENTIFIED BY 'newPassword';

Помог ли вам данный ответ? 36 Пользователи нашли это полезным (143 голосов)