zoukankan      html  css  js  c++  java
  • mysql修改root密码的多种方法

    方法1: 用SET PASSWORD命令

      mysql -u root

      mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

    方法2:用mysqladmin

      mysqladmin -u root password "newpass"

      如果root已经设置过密码,采用如下方法

      mysqladmin -u root password oldpass "newpass"

    方法3: 用UPDATE直接编辑user表

      mysql -u root

      mysql> use mysql;

      mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

      mysql> FLUSH PRIVILEGES;

    在丢失root密码的时候,可以这样

    [root@mysql ~]# /etc/init.d/mysqld stop
    Shutting down MySQL. SUCCESS!
    
    [root@mysql ~]# mysqld_safe --skip-grant-tables&
    [1] 27426
    [root@mysql ~]# 170220 18:48:38 mysqld_safe Logging to '/application/mysql/data/mysql.err'.
    170220 18:48:38 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data
    
    [root@mysql ~]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.5.49 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> UPDATE mysql.user SET password=PASSWORD("oldboy123") WHERE user='root';
    Query OK, 4 rows affected (0.00 sec)
    Rows matched: 4 Changed: 4 Warnings: 0
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> exit
    Bye

     方法四:

    自己查找路径:

    /etc/mysql/conf.d/

    /etc/mysql/mysql.conf.d/

  • 相关阅读:
    一些坑点
    [Luogu P4168] [Violet]蒲公英 (分块)
    冬令营颓废笔记
    WC2019 填坑记
    [Luogu P1829] [国家集训队]Crash的数字表格 / JZPTAB (莫比乌斯反演)
    [Luogu P2522] [HAOI2011]Problem b (莫比乌斯反演)
    [Luogu P3327] [SDOI2015]约数个数和 (莫比乌斯反演)
    [Luogu P3455] [POI2007]ZAP-Queries (莫比乌斯反演 )
    [Luogu P2257] YY的GCD (莫比乌斯函数)
    杭电 1166 敌兵布阵 (线段树)
  • 原文地址:https://www.cnblogs.com/nulige/p/6419502.html
Copyright © 2011-2022 走看看