VI/ETC/MY.CNF #编辑文件, find [mysqld], add a line below Skip-grant-tables
[Mysqld]
Skip-grant-tables
: wq! #保存退出
Service mysqld Restart #重启MySQL服务
2. Enter MySQL Console
Mysql-uroot-p #直接按回车, you do not need to enter the root password.
3. Change the root password
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original Content © Copyright, reproduced please indicate the source and the original link
Update Mysql.user set Password=password (' 123456 ') where user= "root" and host= "localhost";
Flush privileges; #刷新系统授权表
Grant all on * * to ' root ' @ ' localhost ' identified by ' 123456 ' with GRANT option;
4, cancel the/etc/my.cnf in the Skip-grant-tables
VI/ETC/MY.CNF Edit the file, find [mysqld], delete the Skip-grant-tables line
: wq! #保存退出
5. Restart MySQL
Service mysqld Restart #重启mysql, this time the root password of MySQL has been modified to 123456
6. Enter MySQL Console
Mysql-uroot-p #进入mysql控制台
123456 #输入密码
Details: http://www.osyunwei.com/archives/2014.html or http://www.jb51.net/article/39454.htm
Linux forgot MySQL root password solution