当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > mysql数据库root口令忘记自动恢复脚本

Unix/Linux
Linux下构架qmail邮件系统
linux的运行模式:runlevel
在linux7.1上安装jdk+tomcat+oracle9i 笔记
lilo大杂耍
linux下的dns设置详解
使用 find 搜索文件
Linux历史篇
kerneld mini-HOWTO
Linux 核心--16.Linux数据结构
Linux 核心--17.关于Linux的Web与FTP站点 --18.作者简介
Linux 核心--13.Linux动态模块
Linux 核心--14.处理器
Linux 核心--15.Linux内核资源
Linux 核心--12.Linux内核机制
Linux 核心--11.网络
Linux 核心--10.文件系统
Linux 核心--9.设备驱动
Linux 核心--7.PCI设备
Linux 核心--8.中断与中断处理
Linux 核心--6.进程间通讯机制

Unix/Linux 中的 mysql数据库root口令忘记自动恢复脚本


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 178 ::
收藏到网摘: n/a


大家好,最近有用户提出root口令忘记了怎么办的需求,我也在网上看到过好多这样的文章,写的都挺好的,但有些还是有问题,不是少几句话就是执行时出错。我写了一个简单的小脚本,请大家多指教吧。很简单但也很适用。 注意事项: 1。该脚本必须将属主改为root,权限为700,否则有安全问题。 2。该脚本的作用是将root用户的口令清除,若想改口令请用mysqladmin工具来做,或者进入后用update 命令也可 3。此脚本是针对系统自带的mysql命令的。如果是自己安装的源码包,可以修改关于停止mysql的那一部分。 #!/bin/sh #This is programme is recover the password of root for mysql databases. #author is coffee_45 #data is 4月 4 12:14:03 CST 2005 #kill mysqld /bin/kill `cat /var/run/mysqld/mysqld.pid` 2> /dev/null #start mysqld with special paramaters /usr/bin/safe_mysqld --skip-grant-tables & sleep 3 #change password for root chpw_mysql=/home/command_mysql echo "use mysql" >$chpw_mysql 2> /dev/null echo "update user set password=password('') where user='root';" >> $chpw_mysql 2>/dev/null echo "quit" >> $chpw_mysql mysql < $chpw_mysql /etc/init.d/mysqld restart