修改数据库的mysql密码_修改Mysql 数据库的密码

1、修改my.cnf

d0766e736d2d855c255054176bfee785.png

在这个文件里面加入 skip-grant-tables

3b165dfa90ed64e7c3aa9ab5e3f2ee39.png

修改之后,保存。然后重启数据库

2、由于我的系统是Centos7 ,数据库是mariadb ,所以执行命令如下;

64d7d118e0c86e77b52e67721a612fa0.png

3、重启数据库之后,我们再次进入数据库就不需要密码验证了。

4、进入数据库修改密码;

[root@ub1 ~]$ mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)

... ...

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql>

修改更新密码

UPDATE user SET password=PASSWORD('your_new_passwd')WHERE User='root';

值得注意的是mysql和mariadb 是不一样的,在mysql中是没有password这个字段的,要把这个password改成authentication_string;

mysql> UPDATE user SET authentication_string=PASSWORD('root')WHERE User='root';

Query OK, 0 rows affected, 1 warning (0.31 sec)

Rows matched: 1 Changed: 0 Warnings: 1

5、改完密码之后一定记得刷新一下数据库,我之前好多次操作没有成功都是因为没有刷新数据库;

mysql> flush privileges;

6、最后把/etc/my.cnf中的skip-grant-tables注释掉

7、重新启动服务器,密码即可生效。

需要验证密码才能进数据库;

d609bc637e7357fec1ebb57153abe2aa.png

2e421b9c38def59e8a3d0c9110a3a943.png

至此,完成。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值