先登录服务器,找到本身的my.cnf文件,一般会在 /etc目录下(若是不在,能够用find / -name my.cnf命令找一下),而后使用 vi my.cnf 命令编辑该文件(建议先备份),在[mysqld]下面加上 skip-grant-tables ,mysql
做用是登录时跳过登录认证,换句话说就是root什么密码均可以登录进去,而后:wq保存退出后,用service mysqld restart重启mysql。linux
如今不论什么密码均可以登录root用户了。sql
接下来,在Linux中输入以下命令:服务器
# mysql -uroot -p.net
mysql> use mysql;
mysql> update user set password=password('123') where user='root';
mysql> flush privileges; rest
退出mysqlblog
删除skip-grant-tablesip
重启mysql,完成。get