• 忘记mysql超户密码的解决方法


    本文章针对用yum安装的mariadb数据库,如果是tar包安装的mysql数据库,只是数据库命令的关闭启动方式不同而已。

    方法一:
    [root@localhost ~]# killall -u mysql
    [root@localhost ~]# mysqld_safe --skip-grant-tables &
    按一次回车
    [root@localhost ~]# jobs
    [1]+ 运行中 mysqld_safe --skip-grant-tables &
    [root@localhost ~]# mysql
    MariaDB [(none)]> use mysql
    MariaDB [mysql]> update user set password=password('111111') where user='root';

    mysql 5.7以上的版本请使用以下命令:

    MariaDB [mysql]> update user set authentication_string=password('111111') where user='root';
    MariaDB [mysql]> flush privileges;
    MariaDB [mysql]> exit
    [root@localhost ~]# ps
    PID TTY TIME CMD
    8115 pts/0 00:00:00 bash
    10021 pts/0 00:00:00 mysqld_safe
    10193 pts/0 00:00:00 ps
    [root@localhost ~]# kill -9 10021
    [root@localhost ~]# ps
    PID TTY TIME CMD
    8115 pts/0 00:00:00 bash
    10195 pts/0 00:00:00 ps
    [1]+ 已杀死 mysqld_safe --skip-grant-tables
    [root@localhost ~]# mysql -uroot -p'111111'

    方法二:
    [root@localhost ~]# vim /etc/my.cnf
    添加:
    [mysqld]
    port=3306
    socket=/tmp/mysql.sock
    skip-external-locking
    skip_grant_tables
    [root@localhost ~]# killall -u mysql
    [root@localhost ~]# systemctl start mariadb
    [root@localhost ~]# mysql
    MariaDB [(none)]> update mysql.user set password=password('123123') where user='root';
    MariaDB [(none)]> flush privileges;
    MariaDB [(none)]> exit
    [root@localhost ~]# vim /etc/my.cnf
    删除添加的五行:
    [root@localhost ~]# mysql -uroot -p'123123'

  • 相关阅读:
    16、使用limit offset 分页时,为什么越往后翻越慢?如何解决?
    字符串的排列
    从上往下打印二叉树
    栈的压入、弹出序列
    二叉树的镜像
    合并两个排序的链表
    链表中倒数第K个结点
    调整数组顺序使奇数位与偶数前面
    在O(1)时间删除链表结点
    从头到尾打印链表
  • 原文地址:https://www.cnblogs.com/lyqlyqlyq/p/11652850.html
Copyright © 2020-2023  润新知