1)首先编辑mysql的主配置文件 vim /etc/my.cnf
2)在[mysqld]字段下加入skip-grant
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8(放在这条语句后面,)
skip-grant
3)重启mysql服务。/etc/init.d/mysqld restart
4)登入mysql ,直接回车进入mysql /usr/local/mysql/bin/mysql -uroot -p
5)更改密码;
mysql> use mysql;
mysql>update mysql.user SET password=PASSWORD("新密码") where user='root';
6)最后删除掉skip-grant,在重启mysql服务就可用新密码登录。
转载于:https://blog.51cto.com/jmucai/1737445