©
This document usesPHP Chinese website manualRelease
首先停止MySQL进程
[root@localhost ~]# /etc/init.d/mysqld stop Shutting down MySQL. [确定]
使用
--skip-grant-tables
参数启动MySQL,忽略授权登陆验证,如下
[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql & [root@localhost ~]# mysql #这里直接使用mysql登录,然后再使用上面的方法修改用户密码 [root@localhost ~]# /usr/local/mysql/bin/mysqladmin shutdown -uroot -p # 使用mysqladmin关闭mysqld进程 Enter password: [root@localhost ~]# service mysqld start # 再次重新登录
关闭MySQL
killall mysqld 或者 /user/local/mysql/bin/mysqladmin -uroot -p shutdown -S /usr/local/mysql/data/3306/mysql.sock
启动时加额外的配置文件my.cnf和 --skip-grant-tables参数
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/data/3306/my.cnf --skip-grant-table &
登录并修改密码
mysql -S /usr/local/mysql/data/3306/mysql.sock # 无密码登录MySQL mysql> update mysql.user set password=password('aaaaaa') where user='root' and host="localhost"; mysql> flush privileges;
关闭进程并重新开启进程进行测试修改结果
[root@localhost ~]# mysqladmin shutdown -S /usr/local/mysql/data/3306/mysql.sock -uroot -p [root@localhost ~]# /usr/local/mysql/data/3306/mysqld start Starting MySQL... mysql -S /data/3306/mysql.sock -uroot -p