First, using mysqladmin to change the password
1.root User no password
# mysqladmin-u root password 123456 # change Password to 123456:
2.root has password (123456), change password to abcdef:
# mysqladmin-u root-p password abcdef
Note that the command will ask you the old password, enter the old password 123456 after the command completes, the password modification succeeds.
Second, the root of the original myql password;
method One: Outside the MySQL system, use mysqladmin
# mysqladmin-u root-p password "test123"
Enter Password: "Enter the original password"
Method two: By logging into the MySQL system,
# mysql-uroot-p Enter Password: "Enter your original password"
mysql> use MySQL; #进入mysql数据库
mysql> Update user set Password=password (' 123456 ') where user= ' root '; #修改root密码为12345
mysql> flush privileges; #刷新权限
mysql> exit;
Third, forget the original MYQL root password
1. Modify the MySQL configuration file
# vim/etc/my.cnf
Join in [MYSQLD] Paragraph
skip-grant-tables #跳过验证
# service mysqld restart #重启MySQL
2. Connect MySQL
# mysql-uroot
Mysql>use MySQL #进入mysql数据库
mysql> Update user set Password=password (' 123456 ') where user= ' root '; #修改root密码为12345
mysql> flush privileges; #刷新权限
mysql> exit ;
3. Change back to MySQL configuration file
# vim/etc/my.cnf
Log out of Skip-grant-tables
# service mysqld restart #重启MySQL
This article is from the "Garany.wang" blog, make sure to keep this source http://garany.blog.51cto.com/7342714/1760338
MySQL Password modification