• 误删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


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

  • 相关阅读:
    剑指offer——其三
    剑指offer——其二
    剑指offer——其一
    数的读法 蓝桥杯练习题 Java
    2017小结及遇见更好的2018
    自然语言处理随笔(一)
    Shell实现Windows回收站功能
    解决win7下vc6.0打开添加文件错误 崩溃
    Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table Storage
    String两种实例化方法的区别
  • 原文地址:https://www.cnblogs.com/ritchy/p/11940485.html
Copyright © 2020-2023  润新知