经常忘记测试机上mysql的root密码,学着写个脚本处理下
2013-10-09 15:54
357 查看
如题,脚本如下:
本文出自 “攀爬者的博客” 博客,请务必保留此出处http://surveying.blog.51cto.com/6141135/1306295
#!/bin/bash confile="/etc/my.cnf" n_passwd="new password" mysql_bin="/etc/init.d/mysqld" client_bin="/usr/bin/mysql" # Backup Config File cp ${confile} ${confile}_bak # skip grant sed -i '/\[mysqld\]/ a skip-grant-tables' $confile # restart mysqld ${mysql_bin} restart if [ $? -ne 0 ]; then exit -1 fi # connect mysql ${client_bin} <<EOF USE mysql; UPDATE user SET Password = password ( '${n_passwd}' ) WHERE User = 'root' ; flush privileges; exit EOF # restart sed -i '/skip-grant-tables/d' $confile ${mysql_bin} restart diff ${confile} ${confile}_bak >> /dev/null if [ -$? -eq 0 ]; then rm -f ${confile}_bak else echo "Warning: Mysql Config File ${confile} has been changed." echo "Keep Backup as ${confile}_bak." fi
本文出自 “攀爬者的博客” 博客,请务必保留此出处http://surveying.blog.51cto.com/6141135/1306295
相关文章推荐
- MySQL 忘记 root 密码处理办法
- MySQL忘记root密码后的处理
- windows mysql 忘记ROOT密码处理方法
- 简化mysql –uroot –p登录 linux忘记mysql密码处理方法 解决root没有权限
- MySQL忘记root密码处理方法
- Mysql忘记root密码情况的处理
- mysql忘记root密码的处理方式
- mysql忘记root密码的处理方法
- mysql的root密码忘记后的处理办法
- mysql忘记root密码的处理方式
- mysql忘记root密码的处理方法
- Windows下忘记mysql的root密码处理
- 批处理脚本一键重置mysql的root密码
- mysql 忘记root 密码处理方法
- 忘记mysql 5.1 root密码的处理方法
- mysql忘记root密码处理办法
- Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips
- mysql忘记root密码处理办法
- MySQL 忘记root密码的两种处理方法
- MySQL数据库-忘记Mysql的root密码的处理办法