忘记Mysql密码如何找回解决办法
在日常的工作当中肯定会记很多的密码,谁也不会保证密码忘记,丢失这样的情况,今天给大家带来mysql密码忘记或者丢失该如何重设密码,本文章采用的mysql5.7.18版本为例
1.首先kill或者stop停止mysql所有的进程
2.打开mysql主配置文件,添加以下红色字段
[root@yankerp ~]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
socket=/usr/local/mysql/mysql.sock
log_error=/usr/local/mysql/data/mysql.err
skip-grant-tables
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
socket=/usr/local/mysql/mysql.sock
log_error=/usr/local/mysql/data/mysql.err
skip-grant-tables
3.然后启动mysql,用空密码方式使用root用户登录 MySQL
# systemctl start mysqld [root@yankerp ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
4.修改密码
MySQL> update MySQL.user set password=PASSWORD(‘新密码’) where User=’root’;
MySQL>flush privileges;
这时候我们发现它报错了,后来才发现原来是mysql数据库下已经没有password这个字段了,password字段改成了authentication_string这时候我们用authentication_string修改密码如下:
mysql> update mysql.user set authentication_string=password(‘123456′) where user=’root’;
执行完成后退出
5.这时候我们使用修改后的密码登陆mysql数据库