Mysql跳过root密码,并修改root密码方法

1、跳过密码认证

 vim /etc/my.cnf
[mysqld]
skip-grant-tables      //指定位置加一行

改了配置文件,记得重启服务

systemctl restart mysqld       
mysql      //进入到mysql 

mysql> exit

二:更改root密码方式


1:第一种方式
直接在用Linux命令mysqladmin修改。

mysqladmin -u root password "123456"

ubuntu@server:~$ sudo mysqladmin -u root password "123456"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.


2:第二种方式
登录mysql 更改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '654321';

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '654321';
Query OK, 0 rows affected (0.00 sec)

mysql>

3、消除跳过密码认证,进入正常mysql

vim /etc/my.cnf     

把刚刚添加的skip-grant-tables注释或者删除

同样,改了配置文件,要重启服务

 systemctl restart mysqld    

使用新密码登入

 mysql -uroot -p'123456'   

参考文章:https://cloud.tencent.com/developer/article/1661445
         https://blog.csdn.net/weixin_52270081/article/details/121539373

Comments Closed.