A2oz

How to Change MySQL User Password in Ubuntu?

Published in Database Administration 2 mins read

You can change the password for a MySQL user in Ubuntu using the mysql command-line tool. Here's how:

  1. Log in to the MySQL server:

    mysql -u root -p 
    • Replace root with your MySQL root username if it's different.
    • Enter the current password for the MySQL root user when prompted.
  2. Change the password:

    ALTER USER 'username'@'hostname' IDENTIFIED BY 'new_password';
    • Replace username with the name of the user whose password you want to change.
    • Replace hostname with the hostname or IP address of the machine where the user is allowed to connect. If you want to allow the user to connect from any host, use %.
    • Replace new_password with the new password you want to set.
  3. Exit the MySQL shell:

    exit

Example:

To change the password for the user myuser who can connect from the host localhost to newpassword, you would run the following command:

ALTER USER 'myuser'@'localhost' IDENTIFIED BY 'newpassword';

Important Notes:

  • Make sure you have the necessary permissions to modify user accounts in MySQL.
  • Always choose a strong and secure password.
  • If you forget the current password, you might need to reset it using other methods, such as by modifying the MySQL configuration file.

Additional Resources:

Related Articles