修改数据库密码
新搭建的mysql数据库密码存放在 /var/log/mysqld.log中
[root@ecs-ebfb package]# cat /var/log/mysqld.log
2021-10-14T06:38:11.599567Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.26) initializing of server in progress as process 31739
2021-10-14T06:38:11.609140Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-14T06:38:12.105270Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-14T06:38:13.348767Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-10-14T06:38:13.349167Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-10-14T06:38:13.468954Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: %fUa4eMkh-Gt
......
一)当前密码已知的情况下
1)修改当前用户的密码
mysql> set password=password("新密码");
]# mysqladmin -uroot -p password "新密码"
Enter password: 旧密码
2)修改授权用户的密码
mysql> set password for 用户名@‘客户端地址’=passsword(‘新密码’)
3)修改用户密码(mysql8版本适合这个)
mysql> alter user 'root'@'localhost' identified by "密码"
二)当前密码未知的情况下
1)修改主配置文件/etc/my.cnf 添加一行
]#vim etc/my.cnf
skip-grant-tables
2)重启服务
]# systemctl restart mysqld
3)登录数据库
]# mysql
mysql>update mysql.user set authentication_string=password("新密码")
where user="root" and host="localhost";
mysql> flush privileges;