美文网首页
mysql忘记root密码问题

mysql忘记root密码问题

作者: sunland_0416 | 来源:发表于2020-11-17 11:12 被阅读0次

首先修改配置文件.cnf
安装目录不同,文件位置不同。一般docker启动的配置文件在/etc/mysql/my.cnf
添加一行 skip-grant-tables,然后保存并退出

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
#添加下面这一行配置,是免密登陆
skip-grant-tables

# Custom config should go here
!includedir /etc/mysql/conf.d/

重启mysql服务
然后输入mysql进入mysql命令行

#5.7之前版本
mysql> UPDATE mysql.user SET password=PASSWORD('123456') where USER='root';
#5.7及之后版本
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root';

然后刷新权限

mysql> flush privileges;

退出

mysql> quit;

相关文章

网友评论

      本文标题:mysql忘记root密码问题

      本文链接:https://www.haomeiwen.com/subject/xbqzbktx.html