zoukankan      html  css  js  c++  java
  • mysql 忘记本地密码

    MySQL本地管理员忘记密码

    解决办法

    1.重启数据库到无验证模式

    [root@oldboy ~]# vim /etc/my.cnf 
    [root@oldboy ~]# cat /etc/my.cnf 
    [mysqld]
    user=mysql
    basedir=/usr/local/mysql
    datadir=/data/3306/data
    port=3306
    socket=/tmp/mysql.sock
    skip-grant-tables
    skip-networking
    [client]
    socket=/tmp/mysql.sock
    [root@oldboy ~]# systemctl restart mysqld.service 
    

    2.修改登录密码

    [root@oldboy ~]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 7
    Server version: 8.0.20 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2020, 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> 
    mysql> flush privileges;   #重新加载授权表
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> alter user root@'localhost' identified by '123456';
    Query OK, 0 rows affected (0.00 sec)
    [root@oldboy ~]# vim /etc/my.cnf 
    [root@oldboy ~]# cat /etc/my.cnf 
    [mysqld]
    user=mysql
    basedir=/usr/local/mysql
    datadir=/data/3306/data
    port=3306
    socket=/tmp/mysql.sock
    [client]
    socket=/tmp/mysql.sock
    

    3.正常启动数据库

    [root@oldboy ~]# systemctl restart mysqld.service 
    [root@oldboy ~]# mysql -uroot -p123456
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 8
    Server version: 8.0.20 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2020, 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> 
    
    
  • 相关阅读:
    常用类型转换
    配置相关的一些辅助类
    Java Class与反射相关的一些工具类
    一些中文相关的操作方法
    提供一些对象有效性校验的方法
    编码相关的封装类
    数组相关的工具类
    提供Web相关的个工具类
    URL相关的工具类
    经纬度相关的一些操作
  • 原文地址:https://www.cnblogs.com/lailaoban/p/14718117.html
Copyright © 2011-2022 走看看