• mysql忘记root密码做法


    skip-grant-tables的解法

    首先,关闭实例

    这里,只能通过kill mysqld进程的方式。

    注意:不是mysqld_safe进程,也切忌使用kill -9。

    # ps -ef |grep mysqld
    root      6220  6171  0 08:14 pts/0    00:00:00 /bin/sh bin/mysqld_safe --defaults-file=my.cnf
    mysql      6347  6220  0 08:14 pts/0    00:00:01 /usr/local/mysql57/bin/mysqld --defaults-file=my.cnf --basedir=/usr/local/mysql57 --datadir=/usr/local/mysql57/data --plugin-dir=/usr/local/mysql57/lib/plugin --user=mysql --log-error=slowtech.err --pid-file=slowtech.pid --socket=/usr/local/mysql57/data/mysql.sock --port=3307
    root      6418  6171  0 08:17 pts/0    00:00:00 grep --color=auto mysqld

    # kill 6347

    使用--skip-grant-tables参数,重启实例

    bin/mysqld_safe --defaults-file=my.cnf --skip-grant-tables  --skip-networking &

    # mysql -S /usr/local/mysql57/data/mysql.sock
    修改密码
    mysql> update mysql.user set authentication_string=password('123456') where host='localhost' and user='root';
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 0  Warnings: 1

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    修改密码后,打开mysql客户端连接数据库,执行操作时会提示需要更改密码

    set password for root@'localhost'=password('123456');

    最后,重启数据库

    注意:

    这里的update语句针对的是MySQL 5.7的操作,如果是在5.6版本,修改的应该是password字段,而不是authentication_string。
    update mysql.user set password=password('123456') where host='localhost' and user='root';

    而在MySQL 8.0.11版本中,这种方式基本不可行,因为其已移除了PASSWORD()函数及不再支持SET PASSWORD ... = PASSWORD ('auth_string')语法。

    不难发现,这种方式的可移植性实在太差,三个不同的版本,就先后经历了列名的改变,及命令的不可用。

    其他方法参考:

    https://www.cnblogs.com/ivictor/p/9243259.html

  • 相关阅读:
    System.BadImageFormatException: 未能加载文件或程序集""或它的某一个依赖项。试图加载格式不正确的程序。
    Win10中解决SYSTEM权限获取,删Windows old
    Jenkins配置MSBuild编译.net4.6的项目
    TeamViewer11的安全设置
    Jenkins配置的邮件无法发送的问题
    Jenkins 2.x版本修改启动端口号(Windows)
    Jenkins 2.x版本的安装步骤(Windows)
    CruiseControl.NET/CCNET安装包下载
    Jenkins+CCNET的另类部署图
    VisualSVN Server和Subversion的联系
  • 原文地址:https://www.cnblogs.com/allmdzz/p/11296442.html
Copyright © 2020-2023  润新知