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> 
    
    
  • 相关阅读:
    科学计算和可视化,做数据分析与雷达图。
    Leetcode 429 N叉树的层序遍历
    Leetcode 867转置矩阵
    Leetcode 832 翻转图像
    Leetcode 1052 爱生气的书店老板
    Leetcode 337打家劫舍 III
    Leetcode 766 托普利茨矩阵
    Leetcode 1438绝对差不超过限制的最长连续子数组
    Leetcode 697 数组的度
    Leetcode 567 字符串的排列
  • 原文地址:https://www.cnblogs.com/lailaoban/p/14718117.html
Copyright © 2011-2022 走看看