忘记Mysql的root用户密码处理方法(以mysql 5.5.33为例)

1.修改mysql服务器的脚本

~]#vi /etc/rc.d/init.d/mysqld
#找到$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/d
ev/null 2>&1 & wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?此行后,添加--skip-grant --skip-networking
修改后的如下所示
$bindir/mysqld_safe --datadir="$datadir" --skip-grant --skip-networking --pid-file="$mysqld_pid_file_path" $other_args >/d
ev/null 2>&1 &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?

1585295271082

2.将mysql服务重新启动

~]#service mysqld restart

1585295899384

3.更新或修改mysql的root用户密码

~]#mysql>USER mysql
~]#mysql>UPDATE user SET password=PASSWORD('mypasshao') WHERE user='root';

1585296030339

4.重新把mysql服务器的启动服务脚本删除--skip-grant和--skip-networking

~]#vi /etc/rc.d/init.d/mysqld
#找到如下此段
$bindir/mysqld_safe --datadir="$datadir" --skip-grant --skip-networking --pid-file="$mysqld_pid_file_path" $other_args >/d
ev/null 2>&1 &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
#把--skip-grant和--skip-networking删除

5.再次重启mysql服务

~]#service mysqld restart
posted on 2020-03-27 16:12  杨枫哥  阅读(308)  评论(0编辑  收藏  举报