centos设置mysql root密码

时间:2021-09-25 16:18:49

1. service mysqld stop

2. vi /etc/my.cnf

3.在[mysqld]片段中开始新增skip-grant-tables,保存退出vi

4.service mysqld start

5.mysql -u root mysql,进入mysql

6.mysql>use mysql;

7.mysql>update user set password=PASSWORD(’111111’) where user=’root’;

如果找不到password字段,是因为mysql5.7版本password字段改成了authentication_string,用以下语句即可

mysql>update user set authentication_string=password('111111') where user='root' ;

7.mysql>flush privileges;

8.mysql>quit;

9.vi /etc/my.cnf,删除skip-grant-tables,保存退出vi

10.service mysqld start

11.mysql -u root -p,此时输入密码即可。