# 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:
- Login to MySQL as the root user (without a password):
bash
mysql -u root
- 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. - Flush privileges to apply the changes:
sql
FLUSH PRIVILEGES;
- 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.