How to set a root password if there is on root password

# mysqladmin -u root password newpassword

If you want to set a root password for MySQL when there is no root password, you can follow these steps:

  1. Login to MySQL as the root user (without a password):
    bash
    mysql -u root
  2. Set a new password for the root user:
    sql
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';

    Replace your_new_password with the desired password.

  3. Flush privileges to apply the changes:
    sql
    FLUSH PRIVILEGES;
  4. Exit the MySQL shell:
    sql
    exit;

After completing these steps, the root user should have the new password you specified. Make sure to replace your_new_password with a strong and secure password.