mysql 5.5版本 忘记root密码
#################
一,找到mysqld进程并关闭mysql服务:
[work@xxx ~]$ ps aux|grep mysqld work 20209 0.0 0.0 113308 3320 ? S Dec02 0:00 /bin/sh /home/work/mysql/bin/mysqld_safe --defaults-file=/home/work/mysql/etc/my.cnf work 20238 0.0 0.0 112648 2296 pts/0 S+ 10:08 0:00 grep --color=auto mysqld work 21139 11.0 1.5 15143040 1000308 ? Sl Dec02 113:14 /home/work/mysql/bin/mysqld --defaults-file=/home/work/mysql/etc/my.cnf --basedir=/home/work/mysql --datadir=/home/work/mysql/data --plugin-dir=/home/work/mysql/lib/plugin --log-error=/home/work/mysql/log/mysql.err --open-files-limit=10240 --pid-file=/home/work/mysql/data/mysqld.pid --socket=/home/work/mysql/tmp/mysql.sock --port=3306
二,添加skip-grant-tables配置项启动mysql服务:可以通过配置文件my.cnf,也可以通过命令行添加:
# cat my.cnf
[mysqld] skip-grant-tables # generic configuration options port = 3306 socket = /home/work/mysql/tmp/mysql.sock datadir = /home/work/mysql/data user = work
通过配置文件:
# /bin/sh /home/work/mysql/bin/mysqld_safe --defaults-file=/home/work/mysql/etc/my.cnf &
通过命令行:
/bin/sh /home/work/mysql/bin/mysqld_safe --defaults-file=/home/work/mysql/etc/my.cnf --skip-grant-tables &
三,更新密码:
update mysql.user set password=password('123456') where user='root';
四,关闭mysql服务,去掉skip-grant-tables配置,再启动:
#####################