一、实验环境

CentOS Linux release 7.5.1804 (Core)

mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1

二、实施方案

第一步:添加--skip-grant-tables

在/etc/my.cnf.d/server.cnf中[mysqld]下面添加选项

[mysqld]
skip-grant-tables

第二步:重启数据库

[root@ken ~]# systemctl restart mariadb

第三步:登录数据库

现在发现可以在不输入密码的情况下直接登录进数据库

[root@ken ~]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

第四步:修改密码

这个时候使用grant修改密码会报如下的错误

MariaDB [(none)]> grant all on *.* to root@'localhost' identified by '123';
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

使用set修改密码也会报同样的错误

MariaDB [(none)]> set password for root@localhost=password('123');
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

现在使用update即可进行修改

MariaDB [(none)]> use mysql;   #切换至mysql数据库
Database changed MariaDB [mysql]> update user set password=password('123') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4 Changed: 3 Warnings:

第五步:注销掉配置文件中的选项

[root@ken ~]# vim /etc/my.cnf.d/server.cnf
...
[mysqld]
#skip-grant-tables

第六步:重启数据库

[root@ken ~]# systemctl restart mariadb

第七步:再次登录进行验证

现在不输入密码被直接拒绝

[root@ken ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

输入密码123即可进行登录

[root@ken ~]# mysql -uroot -p123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

忘记mysql或mariadb数据库的密码之解决方案的更多相关文章

  1. 忘记mysql或mariadb数据库密码的解决方案

    主机环境 主机系统:

  2. Python使用MySQLConnector/Python操作MySQL、MariaDB数据库

    使用MySQL Connector/Python操作MySQL.MariaDB数据库   by:授客 QQ:1033553122 因目前MySQLdb并不支持python3.x,而MySQL官方已经提 ...

  3. 安装mysql后无法找到临时密码的解决方案

    安装mysql后无法找到临时密码的解决方案 一.环境 系统:CentOS7mysql:5.7.20 二.解决步骤 step1:修改/etc/my.cnf添加: skip-grant-tables   ...

  4. MySQL/MariaDB数据库忘掉密码解决办法--技术流ken

    前言 有些时候我们常常会忘掉一些服务的密码,比如系统密码,我们可以进入救援模式进行修改密码,可参考我之前的博客<Centos7破解密码的两种方法--技术流ken>.但有些时候我们也会忘掉数 ...

  5. 忘记 MySQL 的 root 帐号密码该怎么办

    如果你忘了 MySQL 的 root 帐号密码,别担心,使用下面步骤就可以重设一个新密码: 首先停止 MySQL 服务 “/etc/init.d/mysql stop” 启动 MySQL 服务并屏蔽用 ...

  6. Ubuntu16.04忘记MySQL5.7的root用户密码之解决方案

    其实也就四步,如下: 修改配置文件 sudo vimi /etc/mysql/mysql.conf.d/mysqld.cnf 并在 在[mysqld]下方的skip-external-locking下 ...

  7. 解决忘记mysql中的root用户密码问题

    如果忘了数据库中的root密码,无法登陆mysql. 解决步骤: 1. 使用“--skip-grant-tables”启动数据库 ~]#systemctl stop mysql ~]#mysqld_s ...

  8. 忘记 mysql5.5.24 数据库 root 密码

    兹整理如下,供网友参考 第一步:关闭mysql服务 第二步:新建txt 写入如下内容 UPDATE mysql.user SET Password=PASSWORD('blog.const.net.c ...

  9. 忘记sql server 2008 sa的密码的解决方案

      解决的办法的前提是:可以混合模式登陆1.用windows身份验证登陆.2.新建查询3.输入 EXEC sp_password NULL, 'newPassword', sa搞定了

随机推荐

  1. Hadoop_24_MapReduce实现QQ共同好友

    1.社交粉丝数据分析: 以下是qq的好友列表数据,冒号前是一个用户,冒号后是该用户的所有好友(数据中的好友关系是单向的) A:B,C,D,F,E,O B:A,C,E,K C:F,A,D,I D:A,E ...

  2. invalid argument "type=bind,source=/tmp/tfserving/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu," for "--mount" flag: invalid field '' must be a key=value pair

    --mount参数后面不要有空格 空格去掉即可

  3. laravel事件监听器

    在EventServiceProvide文件里注册事件和监听 protected $listen = [ 'App\Events\SendPhoneCodeEvent' => [ 'App\Li ...

  4. SQL Server 基础:ADO.NET

    序言 Connection 主要提供与数据库的连接功能 Command 用于返回数据.修改数据.运行存储过程以及发送或检索参数信息的数据库命令 CommandType 获取或设置Command对象要执 ...

  5. TTTTTTTTTTTTTTTTTT Gym 100851L 看山填木块

    题意:这题是给你w列方格,然后给你n个方块,让你加进去,使得这个图变得最高,加的要求是,如果这块的下面,以及左下右下都有,才能放 #include <cstdio> #include &l ...

  6. [Luogu] 维护序列

    https://www.luogu.org/problemnew/show/P2023 线段树双懒标记下放 #include <bits/stdc++.h> using namespace ...

  7. 【luoguP3243】[HNOI2015]菜肴制作--拓扑排序

    题目描述 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高到低给予1到N的顺序编号,预估质量最高的菜肴编号为1. 由于菜肴 ...

  8. typedef struct和指针

    在学习链表时遇到了typedef已经用typedef定义的指针,不是很懂,某浪里有位博主的博文写的很详细,我直接粘过来 假设我们定义一个结构体: typedef struct ANSWER_HEADE ...

  9. 一 、Linux基础命令及使用帮助

    linux的哲学思想: 一切皆文件: 把几乎所有资源,包括硬件设备都组织为文件系统 由众多单一目的小程序组成:一个程序只实现一个功能,而且要做好 组合小程序完成复杂任务 尽量避免跟用户交互 目的:实现 ...

  10. INNER JOIN连接两个表、三个表、五个表的SQL语句

    1.连接两个数据表的用法: FROM Member INNER JOIN MemberSort ON Member.MemberSort=MemberSort.MemberSort 语法格式可以概括为 ...