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

Unix/Linux
linux 操作技巧收集_
linux下如何读取使用iso 镜像文件的方法
Linux平台下文件的压缩与解压参数说明
Linux下常用压缩格式的压缩与解压方法
Linux JDK,TOMCAT安装及环境设置
Linux sleep命令使用参数
Linux cat命令参数
nfs 配置的简单例子
linux kill 关闭进程命令
linux ultrasphinx Anonymous modules have no name to be referenced by
Linux oracle 9i图文安装方法一
Linux oracle 9i图文安装教程二
Linux oracle 9i图文安装教程三
Linux oracle 9i图文安装教程四
Linux oracle 9i图文安装教程五
Linux oracle 9i图文安装教程六 完结篇
linux AS3 oracle9i 安装指南
Linux 下 (RedHat 9.0) JDK,Tomcat,MySQL的安装
RedHat 9.0下Apache+PHP+MySQL服务器安装配置
Linux 下用 Python 连接 MSSql Server 2008

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 55 ::
收藏到网摘: 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