zoukankan      html  css  js  c++  java
  • 误删mysql root账户

    看这个账户有点碍眼就删除了,结果异常了
    mysql> select user,host from mysql.user;
    +---------------+-------------+
    | user | host |
    +---------------+-------------+
    | repmha | 192.168.5.% |
    | mysql.session | localhost |
    | mysql.sys | localhost |
    | root | localhost |
    +---------------+-------------+
    4 rows in set (0.00 sec)

    mysql> drop user root@'localhost';
    Query OK, 0 rows affected (0.01 sec)

    登录异常:库中已没了root用户
    [root@test110 ~]# mysql -uroot -p123456
    mysql: [Warning] Using a password on the command line interface can be insecure.
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    修改异常:现在本身就没root用户所以没法修改,无论哪种方式修改,都要先有
    mysql> set password for 'root'@'localhost' = password('123456');
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    1、修改my.cnf
    vi /etc/my.cnf
    --添加
    skip-grant-tables
    2、重启
    service mysqld restart

    3、登录
    [root@xxxx ~]# mysql -uroot -p123456
    mysql> use mysql;
    Database changed
    mysql> select user , host from user;
    +---------------+-------------+
    | user | host |
    +---------------+-------------+
    | monitor | 192.168.5.% |
    | repmha | 192.168.5.% |
    | mysql.session | localhost |
    | mysql.sys | localhost |
    +---------------+-------------+
    4 rows in set (0.00 sec)
    4、重新添加,有时候会出现错误,可以先flush下
    mysql> grant all on *.* to root@'localhost' identified by '123456';
    Query OK, 0 rows affected, 2 warnings (0.00 sec)

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

    5、root又回来了
    mysql> select user , host from user;
    +---------------+-------------+
    | user | host |
    +---------------+-------------+
    | monitor | 192.168.5.% |
    | repmha | 192.168.5.% |
    | mysql.session | localhost |
    | mysql.sys | localhost |
    | root | localhost |
    +---------------+-------------+
    5 rows in set (0.00 sec)

    6、删除 /etc/my.cnf中 skip-grant-tables ,再重启 service mysqld restart


    没事别瞎胡整,删除动作很危险。

  • 相关阅读:
    数据结构之排序查找算法
    Spring3之IOC
    SQL使用范例
    数据结构之链表操作
    VI的使用
    数据结构之树的操作
    Hibernate学习笔记
    Spring3之AOP
    01.由一个程序开始(一)
    Linux的档案权限及目录配置(一) (2)
  • 原文地址:https://www.cnblogs.com/ritchy/p/11940485.html
Copyright © 2011-2022 走看看