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

Unix/Linux
Linux的使用
Linux下的软件安装
Linux下的硬件安装
Linux学习基础
Linux学习指导
Linux值得信任吗?
Linux 管理员手册(2)
Linux 管理员手册(3)
Linux 管理员手册(4)
Linux 管理员手册(5)
Linux 管理员手册(6)
Linux 管理员手册(7)
Linux 管理员手册(8)
Linux 管理员手册(9)
Linux新技术对象存储文件系统
Linux系统文件命令精通指南
Linux基础知识99问(五)
Linux基础知识99问(四)
Linux基础知识99问(三)
Linux基础知识99问(二)

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


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