1、停止mysql : service mysqld stop
2、配置文件中添加 skip-grant-tables
一般在/etc目录下,运行命令:vi /etc/my.cnf,编辑文件
在【mysqlId】 下添加 skip-grant-tables
3、启动msyql : service mysqld start
4、连接 mysql mysql -uroot -h 127.0.0.1 -p
直接回车
5、更改密码:
update mysql.user set authentication_string=password('123') where user='root' and Host ='localhost';
flush privileges;
quit; --- 退出mysql,
可直接重连测试是否密码生效:(mysql mysql -uroot -h 127.0.0.1 -p 输入设置的密码)
7、停止 mysql
8、把vi /etc/my.cnf 中 skip-grant-tables 注释掉。
9、启动mysql
10、有需求 开启远程连接(修改数据库名为mysql 表为 user中的host字段 改为%所有)
查看用户权限并修改;
select user ,host from mysql.user;
update mysql.user set Host='%' where User ='root' limit 1;
flush privileges;
11、查看 用户的去权限信息 mysql> select user ,host from mysql.user;