mysql 5.7忘记密码

Posted on 2020-09-16 09:48  风行天下-2080  阅读(100)  评论(0编辑  收藏  举报

1、

https://blog.csdn.net/zzzcl112/article/details/80484495?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

以上的修改密码改为了命令:

UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';

否则会报错;

————————————————

方法二:

该方法先修改mysql配置文件使其可以无密码登录,让后修改密码,之后便复原配置文件

修改/etc/my.cnf

vim /etc/my.cnf 

配置文件添加skip-grant-tables

[root@VM_0_8_centos ~]# vim /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables                       此处!!!!!!
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

保存后重启mysql

systemctl restart mysql

即可免密登录,命令行输入mysql直接登录

选择mysql数据库,输入下列命令重置密码,'new-password'即为所设置密码

USE mysql;
UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';
修改完成后输入exit退出,重新回到/etc/my.cnf该文件删除之前添加语句即可完成

 

Copyright © 2024 风行天下-2080
Powered by .NET 8.0 on Kubernetes