mysql中,root用户密码被遗忘,该如何进行重置?
需求描述:
在mysql的测试环境中,有时候会遇到一段时间之后root用户的密码被遗忘的情况,
这个时候,就是需要对root密码进行重置,不过,在生产环境中,这种情况还是很少见。
环境描述:
操作系统版本:Red Hat Enterprise Linux Server release 6.6 (Santiago)
数据库版本:5.5.57-log
操作过程:
1.使用操作系统用户(mysql)登录系统(这个用户一般为启动mysql的用户,比如:mysql)
[mysql@redhat6 data]$
备注:mysql server是以mysql这个系统用户运行的,所以要登录到操作系统,mysql用户下。
2.通过kill命令,关闭mysql数据库
kill `cat redhat6.pid`
备注:redhat.pid文件存放的mysqld的进程ID,进入到pid所在的目录中,执行以上的命令,kill掉mysqld的进程。pid文件的一般都是.pid为后缀,主机名为前缀。
3.创建初始化文件
echo "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('chuangzhang503');" > mysql-init
备注:
--1)初始化文件的名字叫做mysql-init,这个名字,可自行修改,就是一个文本文件。
--2)密码处填写自己要使用的新的密码。
4.执行启动mysqld服务,使用--init-file参数,执行文件中的命令
mysqld --init-file=/mysql/data/mysql-init &
执行过程:
[mysql@redhat6 data]$ mysqld --init-file=/mysql/data/mysql-init &
[1] 2963
[mysql@redhat6 data]$ 180320 10:11:03 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
180320 10:11:03 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
180320 10:11:03 [Note] mysqld (mysqld 5.5.57-log) starting as process 2963 ...
备注:通过使用--init-file参数启动mysql数据库,已经执行了mysql-init文件中的内容,重置了root@localhost的密码。
5.通过重置后的root密码进行登录
[mysql@redhat6 data]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.5.-log MySQL Community Server (GPL) Copyright (c) , , 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>
备注:root密码已经被重置,可以进行正常的登录。
6.删除创建的初始化文件mysql-init
rm mysql-init
文档创建时间:2018年3月20日10:14:27
mysql中,root用户密码被遗忘,该如何进行重置?的更多相关文章
- 第三篇 ubuntu下,mysql 的root用户密码忘了怎么办?
好长一段时间没有使用ubuntu了,今天进来玩玩,结果连mysql的root用户密码都忘记了.就上网找了一下,发现如下解决办法,试了一下,可行!记录在此,环境问题,是需要注意的. Ubuntu Ser ...
- 忘记Mysql的root用户密码处理方法(以mysql 5.5.33为例)
1.修改mysql服务器的脚本 ~]#vi /etc/rc.d/init.d/mysqld #找到$bindir/mysqld_safe --datadir="$datadir" ...
- mac 安装mysql + 修改root用户密码 + 及报Access denied for user 'root'@'localhost' (using password:YES)解决办法
1.下载MySQL 到mysql的官网http://dev.mysql.com/downloads/mysql/然后在页面中会看到“MySQL Community Server”下方有一个“downl ...
- mysql修改root用户密码
自我总结,欢迎拍砖! 目的:若root用户密码忘记,则需要重新设置root用户的密码. 步骤: 1.找到mysql安装目录下的 my.ini 文件,找到[mysqlId]一行,在下方添加语句:skip ...
- Ubuntu为mysql的root用户密码问题
1.root用户免密码登录mysql Ubuntu装完mysql时,root用户可以免密登录,如果设置的root用户密码忘记了,想要使用root用户免密登录,修改在配置文件的[mysqld]节点下添加 ...
- 删除mysql中root用户恢复方法
1.# service mysqld stop #停止mysql数据库服务 2.# service mysqld start --skip-grant-tables #跳过授权表启动mysql数据库 ...
- mysql(root用户密码设置)
root密码重置 修改root用户的密码: /*登录mysql*/ mysql -uroot -p123 /*切换数据库*/ use mysql /*修改root用户的密码*/ update user ...
- Mysql修改root用户密码 For Mac 报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
环境 Mysql版本:5.7.12 操作系统:OSX 10.11 安装文件:.dmg文件 MySQL:mysql-5.7.12-osx10.11-x86_64.dmg(注意5.7跟之前的字段有些不同, ...
- MySQL忘记root用户密码修改方法
一般来说在MySQL修改用户密码有好几种方法: 1.修改自己的密码可用: set password=password('123456'); 2.修改其它用户的密码可用: set password fo ...
随机推荐
- 【C语言】构造长度可变的二维数组
#include <stdio.h> #include <malloc.h> #include <memory.h> int getArray(int ***p,i ...
- CString转char * ,string
CString头文件#include <afx.h> string头文件#include <string.h> 1.CString转char * CString cstr; c ...
- Install haroopad on centos7
1.Install libs sudo yum install systemd-libs -y 2.Download haroopad goto haroopad1 download bin pack ...
- How do I iterate over a Scala List (or more generally, a sequence) using theforeach method or for loop?
Scala List/sequence FAQ: How do I iterate over a Scala List (or more generally, a sequence) using th ...
- Ubuntu 12.04下jdk的安装与配置
由于要开始在linux下学习jsp的开发,所以就准备自己动手配置一下jdk和tomcat jdk 下载地址: http://www.oracle.com/technetwork/java/javase ...
- Ajax读取XML和JSON数据
Ajax从服务器获取的数据都是字符串,但是通过不同的解析,可以解析为XML或者JSON. 一般来说.使用XML格式的数据比较通用,但是服务器和客户端解析起来都比较复杂一些;而使用JSON语句话,服务端 ...
- js冒泡事件
一.什么是事件冒泡 在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处 理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个 ...
- Linux作为路由器(一)
前言:Linux主机可以作为路由器使用,利用路由转发功能实现不同网络内的主机能够相互通信,利用iptables的SNAT功能来实现企业内网主机访问互联网,下面做个小的实验. 实验环境:VM (1)路由 ...
- 简单的java程序
1.二分查找,java的输入与输出 package com; public class Firstapp{ public static void main(String args[]) { java. ...
- 路由器的LAN口和WAN口有什么区别
路由器WAN接口连接的是外网,拉进来的网线就是接这个接口. 路由器LAN接口是连接的内网,家里如有几台设备需要拉线上网都是从这个接口接出去的. 路由器(Router,又称路径器)是一种计算机网络设 ...