首先我们先查看mysql是否启动
ps -ef | grep -i mysql
启动的话我们就关闭mysql服务
service mysql stop
然后我们更改mysql的配置文件(my.cnf),使其能够无密码登录
my.cnf
配置文件的位置,一般在/etc/my.cnf
,有些版本在/etc/mysql/my.cnf
在配置文件中,增加1行代码
skip-grant-tables
然后就启动mysql服务器
service mysqld start
登录mysql
mysql -u root
在命令行里面输入以下语句
update mysql.user set authentication_string=password('root_password') where user='root';
注意!!!root_password这个是你的密码,请自行修改!!。最后再重启一下mysql服务就可以了