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

    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/

  • 相关阅读:
    安装node.js webkit环境[一]
    wpf 窗口最小化后,触发某事件弹出最小化窗口并置顶
    c# 旋转图片 无GDI+一般性错误
    类库里面添加日志记录 log4net
    string转xml
    DES c#加密后java解密
    使用排序字典排序
    怎么让一段xml被识别为字符串
    新装iis 页面503错误 DefaultAppPool停止解决方案
    hession
  • 原文地址:https://www.cnblogs.com/dengbingbing/p/10429066.html
Copyright © 2011-2022 走看看