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

MySQL root User Change Ordinary User Password

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.

  1. MySQL root user change password for ordinary user:

    • Description: Changing the password for an ordinary user by the MySQL root user involves using the SET PASSWORD statement.
    • Code:
      SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
      
  2. Allow root user to modify ordinary user password in MySQL:

    • Description: Granting the UPDATE privilege on the mysql.user table allows the root user to modify the password for an ordinary user.
    • Code:
      GRANT UPDATE ON mysql.user TO 'root'@'localhost';
      FLUSH PRIVILEGES;
      
  3. Changing password for another user with MySQL root:

    • Description: As the root user, you can change the password for any user using the SET PASSWORD statement.
    • Code:
      SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
      
  4. MySQL root user set password for ordinary user:

    • Description: The MySQL root user can set the password for an ordinary user using the SET PASSWORD statement.
    • Code:
      SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
      
  5. Granting privileges to MySQL root for password changes:

    • Description: Granting the UPDATE privilege on the mysql.user table allows the root user to modify user passwords.
    • Code:
      GRANT UPDATE ON mysql.user TO 'root'@'localhost';
      FLUSH PRIVILEGES;
      
  6. Modifying user password as root in MySQL:

    • Description: The root user can modify any user's password using the SET PASSWORD statement.
    • Code:
      SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
      
  7. MySQL root user update password for other users:

    • Description: As the root user, you have the authority to update the password for any user using the SET PASSWORD statement.
    • Code:
      SET PASSWORD FOR 'ordinary_user'@'hostname' = PASSWORD('new_password');
      
  8. Enabling root to change password for ordinary user in MySQL:

    • Description: Granting the UPDATE privilege on the mysql.user table allows the root user to modify passwords.
    • Code:
      GRANT UPDATE ON mysql.user TO 'root'@'localhost';
      FLUSH PRIVILEGES;
      
  9. MySQL grant root privileges to update user password:

    • Description: Granting the UPDATE privilege on the mysql.user table allows the root user to update passwords for other users.
    • Code:
      GRANT UPDATE ON mysql.user TO 'root'@'localhost';
      FLUSH PRIVILEGES;