[How to] set a password for mysql root user

10. September 2013 SysAdmin 0

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,
root@JobNix:~# mysql

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.

`vi /root/.my.cnf`
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.

root@JobNix:~# mysql

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)

0 0 votes
Article Rating

Notify of
Inline Feedbacks
View all comments