Sunday, February 16, 2014

How to change a password in MySQL

Overview

Often, people are wondering how to change a password in MySQL.

How to change the root password

Root Password

  • After first installation
 After the first installation and the first startup the root password should be changed using

mysqladmin -u root password 'new_root_password'

if the password already exists

mysqladmin -u root -p'oldpassword' password newpassword

Once the root password changed you should change it for all root accounts using the mysql_secure_installation
  • Change password using mysqladmin
mysqladmin -u user -p'oldpassword' password 'newpassword'

  • Here how to change a password in MySQL
Make sure you are connected to a database
use mysql;

    • Change the password for all user where user = 'username'

update user set password=PASSWORD('newpassword') where user='username';
flush privileges;

    • Change the password for a specific user
update user set password=PASSWORD('newpassword') where user='username' and host='hostname';
EX:  update user set password=PASSWORD('changeme') where user='user1' and host='%';
update user set password=PASSWORD('changeme') where user='user1' and host='192.168.0.10';

or

set password for useryouwanttochange = PASSWORD ( 'new_password' );






No comments:

Post a Comment