zoukankan      html  css  js  c++  java
  • 【转载】重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

     

    一般这个错误是由密码错误引起,解决的办法自然就是重置密码。

    假设我们使用的是root账户。

    1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下:

    #vim /etc/my.cnf(注:windows下修改的是my.ini)

    在文档内搜索mysqld定位到[mysqld]文本段:
    /mysqld(在vim编辑状态下直接输入该命令可搜索文本内容)

    在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程,如下图所示:

    保存文档并退出:

    #:wq
    2.接下来我们需要重启MySQL:

    /etc/init.d/mysql restart(有些用户可能需要使用/etc/init.d/mysqld restart)

    3.重启之后输入#mysql即可进入mysql。

     

    4.接下来就是用sql来修改root的密码

    mysql> use mysql;
    mysql> update user set password=password("你的新密码") where user="root";
    mysql> flush privileges;
    mysql> quit

    到这里root账户就已经重置成新的密码了。

    5.编辑my.cnf,去掉刚才添加的内容,然后重启MySQL。大功告成!

     网上有很多关于这个问题的解决说明,很多刚接触的朋友可能比较迷惑的是在自己的平台上找不到my.cnf或者my.ini文件,如果你是Linux,使用如下方式可以搜索到:

    至于windows平台,去安装目录下找一下my.ini吧。

    #####

    cyx 20190319  pass 

    ####

    [root@10 mysql-data]# cp  /etc/my.cnf   /etc/my.cnf.bak 

    [root@10 mysql-data]# cat /etc/my.cnf

    [mysqld]

    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

    # 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

    [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

    [root@10 mysql-data]#

     #systemctl restart mariadb

  • 相关阅读:
    进程和阻塞
    docker简介
    python===lambda匿名函数===day15
    python----生成器, 生成器函数, 推倒式---13
    python----函数参数---10天
    python---函数 第九天
    python===文件===第八天
    python===基本数据类型 基本增删改查 ===深浅拷贝==第七天
    20180802 (个别内置方法)
    20180730 (面向对象的反射,内置方法)
  • 原文地址:https://www.cnblogs.com/xuanbjut/p/10407172.html
Copyright © 2011-2022 走看看