How to change MySQL user's new password

From PheonixSolutions
Jump to navigation Jump to search

How to change MySQL user's new password

Introduction

To change a MySQL user's password, you can use the following steps:

Step:1

Log in to MySQL: Access the MySQL command-line interface as a user with sufficient privileges, such as the root user.

 mysql -u root -p

Step: 2

The query SELECT * FROM mysql.user; retrieves information about all users stored in the mysql.user table in MySQL. Here's how you can execute this query

 SELECT * FROM mysql.user;

Step:3

To change the password for the user 'SuperUser', you can use the SET PASSWORD command.

 SET PASSWORD FOR 'testuser'@'%' = PASSWORD('fD0jJTRdZ');

Step:4

To grant all privileges on all databases to a user named 'testuser' from any host (%), along with the ability to grant these privileges to other users, you can use the following SQL command:

 GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'%' WITH GRANT OPTION;

Step:5

To grant all privileges on all databases to a user named 'SuperUser' and specify a password, you can use the GRANT statement in MySQL. Here's the syntax for granting all privileges:

 GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost' IDENTIFIED BY 'fD0jJTRdZ' WITH GRANT OPTION;

This statement will grant full privileges on all databases to the 'testuser' when connecting from any host. The WITH GRANT OPTION part allows 'testuser' to grant these same privileges to other users if needed.

Step:6

After executing this command, don't forget to flush privileges for the changes to take effect immediately:

 FLUSH PRIVILEGES;

Please ensure that you use appropriate caution when granting such broad privileges, especially with the WITH GRANT OPTION, as it allows the user to grant privileges to others, potentially escalating their privileges across the system.