mysql多实例修改忘记的root密码

一、操作思路:

1)停止mysql服务

2)启动时添加“--skip-grant-tables”参数

3)修改密码

4)重启mysql服务

二、执行过程

# netstat -tunlp | grep 330*
tcp        0      0 0.0.0.0:3306                0.0.0.0:*         LISTEN      13157/mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*         LISTEN      13874/mysqld        
tcp        0      0 0.0.0.0:3308                0.0.0.0:*         LISTEN      12388/mysqld 
# 这里假设忘记的是3308实例的root密码
# 先安全关闭另外两个实例
# /data/3306/mysql stop
# /data/3307/mysql stop
# killall mysqld
# mysqld_safe --defaults-file=/data/3308/my.cnf --skip-grant-tables &
[2] 10883
# 161011 22:05:47 mysqld_safe Logging to ‘/data/3308/mysql_oldboy3308.err‘.
161011 22:05:48 mysqld_safe Starting mysqld daemon with databases from /data/3308/data
# mysql -uroot -p -S /data/3308/mysql.sock
Enter password: (这里直接回车就进去了)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> update mysql.user set password=password("redhat123456") where user=‘root‘;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
# 更新root账号的密码
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 刷新权限
# netstat -tunlp | grep mysql
tcp        0      0 0.0.0.0:3308                0.0.0.0:*                   LISTEN      11620/mysqld        
[1]+  Done                    mysqld_safe --default-file=/data/3308/my.cnf --skip-grant-tables --user=mysql
# pkill mysql
# netstat -tunlp | grep mysql
# /data/3308/mysql start
Starting MySQL...
# echo $?
0

三、验证

# mysql -uroot -predhat123456 -S /data/3308/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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>
时间: 2024-08-04 04:05:38

mysql多实例修改忘记的root密码的相关文章

Linux忘记登录/root密码的修改方法

因为朋友的一台Linux密码忘记了,让我帮忙搞定,搞定后感觉,这个方法可能以后依旧能用上,总结一下进行记录,方便以后的使用. Linux版本为:Ubuntu 14.04 第一步开机到grub 第二步点进ubuntu高级设置后如下 第三步进到recovery mode恢复模式(注意这一步是按e而不是回车) 这个是进入后的效果 第四步找到ro recovery mode 将其修改成为rw single init=/bin/bash 然后ctrl+x就可以进入 部分界面如下: 在这界面下你用 pass

vCenter Server Appliance 6.5 中重置丢失或忘记的 root 密码

vCenter Server Appliance 6.5 中重置丢失或忘记的 root 密码 目前安装vCenter Server Appliance 6.5客户原来越多,给用户配置过程中,往往会忽略默认的root 密码策略:60天过期.一旦密码过期或忘记密码,vcsa的管理控制台就无法通过root登录. 以下是参考官方KB 方法修改忘记或过期的root密码. 1.  请先生成 vCenter Server Appliance 6.5 快照或备份,然后再继续.不要跳过该步骤. 2.  重新引导

修改MySQL 5.7.9版本的root密码方法以及一些新变化整理

MySQL 5.7版本开始,增强密码验证机制,网上说安装的时候会在/root/.mysql_secret  文件中生成默认密码,这一点自 5.7.6版本以后也去掉了. 针对如果生成默认密码,网上有一个版本,内容如下: 1.修改配置文件,一般在 /etc/my.cnf, 在[mysqld]字段下增加skip-grant-tables 字段,用以忽略权限验证: 2.重启MySQL服务器,CentOS 7.0操作命令是: 1 systemctl restart mysqld.service 3.使用m

管理员 修改MySQL 5.7.9 新版本的root密码方法以及一些新变化整理

MySQL 5.7版本开始,增强密码验证机制,网上说安装的时候会在/root/.mysql_secret  文件中生成默认密码,这一点自 5.7.6版本以后也去掉了. 针对如果生成默认密码,网上有一个版本,内容如下: 1.修改配置文件,一般在 /etc/my.cnf, 在[mysqld]字段下增加skip-grant-tables 字段,用以忽略权限验证: 2.重启MySQL服务器,CentOS 7.0操作命令是: systemctl restart mysqld.service 3.使用mys

mysql笔记一——安装和设置root密码

1. mysql 5.6安装包下载. MySQL安装文件分为两种,一种是msi格式的,一种是zip格式的.如果是msi格式的可以直接点击安装,按照它给出的安装提示进行安装(相信大家的英文可以看懂英文提示),一般MySQL将会安装在C:\Program Files\MySQL\MySQL Server 5.6 该目录中:zip格式是自己解压,解压缩之后其实MySQL就可以使用了,但是要进行配置. 2. 配置环境变量 我的电脑->属性->高级->环境变量,选择PATH,在其后面添加: mys

Centos7.4 修改MySQL5.7 root 密码

参考博文:http://www.jb51.net/article/100211.htmhttps://www.cnblogs.com/wangbaobao/p/7087032.html 1.vim /etc/my.cnf 2.在[mysqld]中添加 skip-grant-tables 例如: [mysqld] skip-grant-tables datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock 3.重启mysql service m

MySql 5.7 for Windows 重置root密码

原文:https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html 1. 停止mysql服务,如果mysql以window服务安装的则在服务管理器中停止,如果以命令行运行起来的,则需要在任务管理器中强制停止进程. 2. 创建脚本,用于启动mysql的时候加载执行,脚本内容为更改root密码: MySQL 5.7.6 以及之后的版本: ALTER USER 'root'@'loca

mac os x忘记了root密码怎么办,忘记登录密码(普通帐号密码)也是一样的

有时候我们给mac设置了root密码,一段时间不用,却忘记了密码,怎么办?下面的办法帮你解决: 步骤1:先关闭你的mac系统 步骤2:开机,按住Command和s两个按键不松手直到出现下面的界面: 步骤3:上面已经提示你输入的命令了,先输入:/sbin/fsck -fy 然后回车,等待一段时间,再次输入命令:/sbin/mount -uw / 然后回车 步骤4:输入:launchctl load /System/Library/LaunchDaemons/com.apple.opendirect

修改Ubuntu的root密码

不知道大家有没有遇到过安装完Ubuntu后根本没有设置root密码,但是有的时候需要使用root账户进行一些操作.笔者最近就遇到这种情况,经过查询资料,得知Ubuntu的默认root密码会跟着每次开机都会随机生成一组密码,如果想把root密码记住就需要更改密码. 直接使用"sudo passwd"然后输入当前用户的密码后,就可以修改Ubuntu的root用户密码.