码迷,mamicode.com
首页 > 数据库 > 详细

mysql root 密码丢失问题

时间:2016-08-05 11:43:19      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

root密码丢失,我们需要将mysql以不检查权限的方式重新启动。

在mysql的配置文件(/etc/my.cnf)中,[mysqld]下添加一句skip-grant-tables,然后重新启动服务,就可以通过无密码的方式登录。

通过select password(new password);可以查询到加密后的密码,将它替换原来的密码,我们就可以通过新的密码进行操作了。

技术分享

代码如下

vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

skip-grant-tables
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

systemctl restart mariadb

mysql -u root -p

Enter password: (按enter键进入)

use mysql

update user set Password = password(‘000000‘) where user = ‘root‘

\q

vim /etc/my.cnf

删除掉skip-grant-tables

systemctl restart maridb

mysql -u root -p

Enter password:000000

 

mysql root 密码丢失问题

标签:

原文地址:http://www.cnblogs.com/picap00n/p/mysql_1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!