This is how to set a password for mysql root user.
Run the following command to set a password
`/usr/bin/mysqladmin -u root password ‘new-password’`
Once the password is applied, Test it by accessing mysql as root from localhost.
You will get something like this,
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)“`
That means you have successfully applied the password for root user.
Now, create the following file so that you can access mysql from root user from the localhost without a password.
add the following to the file, And
Then save it by :wq!
Secure the password file by running,
`chmod 600 /root/.my.cnf`
Now you can access mysql from root user without password.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 55
Server version: 5.5.32-0ubuntu0.12.04.1 (Ubuntu)“`
That means, You can access mysql from root without any password and all the other local users need a password to access mysql as root from the shell.
Comment if found helpful ![:)](https://www.jobnix.in/wp-includes/images/smilies/icon_smile.gif)