忘记mysql或mariadb数据库的密码之解决方案
一、实验环境
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数据库的密码之解决方案的更多相关文章
- 忘记mysql或mariadb数据库密码的解决方案
主机环境 主机系统:
- Python使用MySQLConnector/Python操作MySQL、MariaDB数据库
使用MySQL Connector/Python操作MySQL.MariaDB数据库 by:授客 QQ:1033553122 因目前MySQLdb并不支持python3.x,而MySQL官方已经提 ...
- 安装mysql后无法找到临时密码的解决方案
安装mysql后无法找到临时密码的解决方案 一.环境 系统:CentOS7mysql:5.7.20 二.解决步骤 step1:修改/etc/my.cnf添加: skip-grant-tables ...
- MySQL/MariaDB数据库忘掉密码解决办法--技术流ken
前言 有些时候我们常常会忘掉一些服务的密码,比如系统密码,我们可以进入救援模式进行修改密码,可参考我之前的博客<Centos7破解密码的两种方法--技术流ken>.但有些时候我们也会忘掉数 ...
- 忘记 MySQL 的 root 帐号密码该怎么办
如果你忘了 MySQL 的 root 帐号密码,别担心,使用下面步骤就可以重设一个新密码: 首先停止 MySQL 服务 “/etc/init.d/mysql stop” 启动 MySQL 服务并屏蔽用 ...
- Ubuntu16.04忘记MySQL5.7的root用户密码之解决方案
其实也就四步,如下: 修改配置文件 sudo vimi /etc/mysql/mysql.conf.d/mysqld.cnf 并在 在[mysqld]下方的skip-external-locking下 ...
- 解决忘记mysql中的root用户密码问题
如果忘了数据库中的root密码,无法登陆mysql. 解决步骤: 1. 使用“--skip-grant-tables”启动数据库 ~]#systemctl stop mysql ~]#mysqld_s ...
- 忘记 mysql5.5.24 数据库 root 密码
兹整理如下,供网友参考 第一步:关闭mysql服务 第二步:新建txt 写入如下内容 UPDATE mysql.user SET Password=PASSWORD('blog.const.net.c ...
- 忘记sql server 2008 sa的密码的解决方案
解决的办法的前提是:可以混合模式登陆1.用windows身份验证登陆.2.新建查询3.输入 EXEC sp_password NULL, 'newPassword', sa搞定了
随机推荐
- META-INF/MANIFEST.MF介绍
META-INF文件夹相当于一个信息包,目录中的文件和目录获得Java 2平台的认可与解释,用来配置应用程序.扩展程序.类加载器和服务.这个文件夹和其中的 MANIFEST.MF文件,在用jar打包时 ...
- [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...
- Error resolving template “pages”, template might not exist or might not be accessible by any of the configured Template Resolver 或者 springboot使用thymeleaf时报html没有结束标签
application.properties配置文件 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.ht ...
- initramfs机制
1.什么是 Initramfs 在2.6版本的linux内核中,都包含一个压缩过的cpio格式的打包文件.当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs ...
- barcode模块: plus.barcode.scan 进行扫描图片出现无法识别二维码,打印的错误信息是code:8,message:''
原因之一:图片的像素太大了,无法识别. 解决方法: 压缩一下图片. 这里的 data 我放了一个 像素为 4040 × 4040 的 图片. 进行识别的时候会报, (无法识别的图片,都是返回这些值) ...
- Spring基础(一)------装配Bean
一.Spring配置的可选方案 三种主要的装配机制: 在xml文件中进行显示配置: 在java中进行显示配置: 隐式的bean发现机制和自动装配. 使用建议:尽可能使用自动配置的机制,显示配置越少越好 ...
- 解决CMD控制台乱码问题
在cmd控制台中出现乱码情况如下 解决方式1 在控制台中输入 CHCP65001 按enter回车键查看 注:CHCP是一个计算机指令,能够显示或设置活动代码页编号. 代码页 描述6500 ...
- Mac出现程序闪退的解决方案
重置PRAM 1. 关机 2.按下电源键后,立即按下command + option + P +R 3.等到电脑出现4次重启的声音后,放开按键,重置成功 4.正常使用
- word文档的图片怎么保存到ueditor上
word图片转存,是指UEditor为了解决用户从word中复制了一篇图文混排的文章粘贴到编辑器之后,word文章中的图片数据无法显示在编辑器中,也无法提交到服务器上的问题而开发的一个操作简便的图片转 ...
- learning armbian steps(8) ----- armbian 源码分析(三)
在lib/main.sh当中 ) == main.sh ]]; then echo "Please use compile.sh to start the build process&quo ...