一、对文件进行设置
1.应该首先去 /etc/mysql/my.cnf路径下的文件,然后用命令编辑my.cnf配置文件。命令如下:
vim my.cnf
nano my.cnf # 这个更好用
2.在[mysqld]下添加skip-grant-tables,然后保存并退出。
看下图做参考:
3.重新启动mysql服务,一个就行。
使用 service 启动:service mysql start
使用 service 关闭:service mysql stop
使用 service 重新启动:service mysql restart
二、下面进入改自己的密码
1.下面直接 使用命令进入mysql这次不用密码,我们得先进去才可以修改。
mysql -uroot -p
2.进入以后开始修改。
方式一:
use mysql
mysql> update user set authentication_string=password(‘123456.’) where user=‘root’; #括号是新密码
mysql> flush privileges; #立即生效
mysql> quit #退出mysql 使用 exit命令也是一样的,以前有区别,现在这俩没区
方式二:
mysql> update user set password=password(“") where user="”;
修改密码报错:
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
原因:
是 5.7版本下的mysql数据库下没有password这个字段,password字段改成了authentication_string扫描二维码关注公众号,回复: 11370169 查看本文章
mysql> update mysql.user set authentication_string=password(‘’) where user='’; #修改密码成功
mysql> flush privileges;
mysql> quit
3.重新执行vim /etc/mysql/my.cnf,然后删除刚刚加入的 skip-grant-tables,重新启动mysql.