How to change the MySql user(root) password


In this MySql tutorial we will learn how to change the MySql user(root) password.




Change MySql user password 1: Changing the root password - When root password is blank (i.e. an empty string).


you can use
SET PASSWORD FOR root@localhost = PASSWORD('new-password');
to set new password.

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root
mysql> SET PASSWORD FOR root@localhost = PASSWORD('new-password');
Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD FOR root@127.0.0.1 = PASSWORD('new-password');
Query OK, 0 rows affected (0.00 sec)

mysql>

or, use
UPDATE mysql.user SET Password = PASSWORD('new-password')
   WHERE User = 'root';
to set new password.
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('new-password')
   ->      WHERE User = 'root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql>



Change MySql user password 2: Changing the root password - When root password is NOT blank.
First you'll have to enter existing password for root user, than you can use
SET PASSWORD FOR root@localhost = PASSWORD('new-password');
to set new password.

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.

mysql> SET PASSWORD FOR root@localhost = PASSWORD('new-password');
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD FOR root@127.0.0.1 = PASSWORD('new-password');
Query OK, 0 rows affected (0.00 sec)

mysql>

or,
use
UPDATE mysql.user SET Password = PASSWORD('new-password')
   WHERE User = 'root';
to set new password.

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.

mysql> UPDATE mysql.user SET Password = PASSWORD('new-password')
   ->      WHERE User = 'root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql>




Change MySql user password 3: Changing the root password using mysqladmin.
First you'll have to enter existing password for root user, than you can enter set new password.

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqladmin -u root -p password
Enter password: ****
New password: *****
Confirm new password: *****

C:\Program Files\MySQL\MySQL Server 5.6\bin>



Change MySql user password 4: UBUNTU/linux user can try this for setting up root password >


sudo dpkg-reconfigure mysql-server-5.6



So in this MySql tutorial we learned how to change the MySql user(root) password.

Related >>

How to reset the forgotten MySql root password

select rows between one number to another in MySql tutorial

How to change the MySql user(root) password tutorial


No comments:

Post a Comment