zoukankan      html  css  js  c++  java
  • mysql 数据库密码忘记重置 进行远程连接

    Mysql忘记密码


    背景

    由于好久之前安装的数据库,密码忘记了(改进方案:最好记录在自己的密码记事本),导致登录不了。

    镜像服务环境

    Linux

    Mysql版本

    5.7.22

    现象

    拒绝用户root访问,请使用正确的密码奥。

    [root@iz2zeezkmfgg9patbo38hmz ~]# mysql -uroot -p
    Enter password:
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    解决办法

    查看mysql是否启动

    [root@iz2zeezkmfgg9patbo38hmz bin]# ps -ef | grep  mysql
    root     4500     1 0 07:24 pts/0   00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/iz2zeezkmfgg9patbo38hmz.pid

    mysql     4669 4500 0 07:24 pts/0   00:00:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/loc
    al/mysql/logs/mysqld.log --pid-file=/usr/local/mysql/data/iz2zeezkmfgg9patbo38hmz.pid --socket=/usr/local/mysql/mysql.sockroot     5464 1575 0 07:47 pts/0   00:00:00 grep --color=auto mysql

    暂停服务

    systemctl stop mysqld.service

    修改配置文件

    vi /etc/my.cnf
    # 在[mysqld]下添加 跳跃密码认证
    skip-grant-tables

    修改密码!关键

    # 启动服务
    systemctl start mysqld.service
    # 进入数据库
    mysql -u root
    # 使用mysql数据库
    mysql> use mysql;
    # 修改数据库信息
    mysql> update mysql.user set authentication_string=password('0000') where user='root';
    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 1
    # 刷新权限认证
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    mysql> exit

    重启服务

    systemctl restart mysqld.service

    重新连接

    mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 12
    Server version: 5.7.22 Source distribution

    Copyright (c) 2000, 2018, 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> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '0000';

     

  • 相关阅读:
    Django Restframework 实践(二)
    mysql in 过滤 解决转义问题
    automapper
    autoface
    各种文件上传 转载
    REST Client
    MySql PartionBy
    mysql 变量名称不能与表字段一致
    mysql 存储过程分页 转载
    dapper.net 转载
  • 原文地址:https://www.cnblogs.com/lingduqianli/p/14952785.html
Copyright © 2011-2022 走看看