By default, MySQL is installed with root user without password. Do you want to change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?
Setting up MySQL password is one of the essential tasks. Root user in MySQL is MySQL admin account user. Please note that the Linux / UNIX root account for your operating system and MySQL root are different. They are separate and nothing to do with each other. Sometime your may remove mysql root account and setup admin as mysql super user for security purpose.
Using mysqladmin command to change root password
If you have never set a root password for MySQL server, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:$ mysqladmin -u root password NEWPASSWORDHowever, if you want to change (or update) a root password, then you need to use the following command:
$ mysqladmin -u root -p'oldpassword' password newpassExample:
If the old password is wayan, you can set the new password to kadek using the following command:
$ mysqladmin -u root -p'wayan' password 'kadek'
Change MySQL password for other users
To change a normal user password you need to type (let us assume you would like to change password for user komang) the following command:$ mysqladmin -u komang -p oldpassword password newpassChanging MySQL root user password using sql command (query syntax)
MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user komang:1) Login to mysql server, type the following command at shell prompt:
$ mysql -u root -p2) Use mysql database (type command at mysql> prompt):
mysql> use mysql;
3) Change password for user komang, enter:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='komang';4) Finally, reload the privileges:
mysql> flush privileges; mysql> quit