MySQL Tutorial
MySQL Installation and Configuration
MySQL Database Operations
Database Design
MySQL Data Types
MySQL Storage Engines
MySQL Basic Operations of Tables
MySQL Constraints
MySQL Operators
MySQL Function
MySQL Manipulate Table Data
MySQL View
MySQL Indexes
MySQL Stored Procedure
MySQL Trigger
MySQL Transactions
MySQL Character Set
MySQL User Management
MySQL Database Backup and Recovery
MySQL Log
MySQL Performance Optimization
As a MySQL root user, you can change the password of any other user in the system. This can be helpful if a user has forgotten their password, or if there's a need to reset it for security reasons.
Here's how you can change an ordinary user's password as a root user:
Step 1: Login to MySQL as root
First, you need to login to MySQL as the root user. Use the mysql
command in your terminal or command prompt:
mysql -u root -p
You'll be prompted to enter the password for the root
user.
Step 2: Change the User's Password
Once you're logged in as root, you can change another user's password with the ALTER USER
command:
ALTER USER 'username'@'hostname' IDENTIFIED BY 'new_password';
Where:
'username'
is the name of the user whose password you want to change.'hostname'
is the host from which the user connects to the database. This is usually 'localhost'
if the user is connecting from the same machine where the MySQL server is running.'new_password'
is the new password you want to set for this user.For example, to change the password of a user named 'bob' who connects from 'localhost', you would do:
ALTER USER 'bob'@'localhost' IDENTIFIED BY 'new_secure_password';
Replace 'new_secure_password'
with the new password.
Step 3: Exit MySQL
You can exit the MySQL shell by typing:
EXIT;
Important:
When changing a user's password, make sure to follow good password security practices. The new password should be strong (a mix of uppercase letters, lowercase letters, numbers, and symbols) and not easily guessable. Never use plain, dictionary words as passwords. Also, inform the user about the password change and make sure they change it to something only they know at the next login.
MySQL root user change password for ordinary user:
SET PASSWORD
statement.SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
Allow root user to modify ordinary user password in MySQL:
UPDATE
privilege on the mysql.user
table allows the root user to modify the password for an ordinary user.GRANT UPDATE ON mysql.user TO 'root'@'localhost'; FLUSH PRIVILEGES;
Changing password for another user with MySQL root:
SET PASSWORD
statement.SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
MySQL root user set password for ordinary user:
SET PASSWORD
statement.SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
Granting privileges to MySQL root for password changes:
UPDATE
privilege on the mysql.user
table allows the root user to modify user passwords.GRANT UPDATE ON mysql.user TO 'root'@'localhost'; FLUSH PRIVILEGES;
Modifying user password as root in MySQL:
SET PASSWORD
statement.SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
MySQL root user update password for other users:
SET PASSWORD
statement.SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
Enabling root to change password for ordinary user in MySQL:
UPDATE
privilege on the mysql.user
table allows the root user to modify passwords.GRANT UPDATE ON mysql.user TO 'root'@'localhost'; FLUSH PRIVILEGES;
MySQL grant root privileges to update user password:
UPDATE
privilege on the mysql.user
table allows the root user to update passwords for other users.GRANT UPDATE ON mysql.user TO 'root'@'localhost'; FLUSH PRIVILEGES;