解决Linux VPS/服务器忘记PHPMYADMIN账户ROOT用户MYSQL密码

由于各种的可能,会导致我们忘记原本设置没有问题的Linux VPS/服务器网站环境中MYSQL数据库PHPMYADMIN账户密码可以登录管理的,也许是因为脑子短路忘记,或者本地备份丢失,以及可能环境出现问题导致密码即便是正确的我们也无法登陆。这样的问题也没有多么复杂,我们只需要根x ` l {据下面的方法重新G p E - o U t j找回密码就可以。

文章目录
隐藏
A - 稍微复杂的方法

B - 稍微简单的方法

A -稍微复杂的方法

第一、登陆SSH修改MYSQL设置

vi /etc/my.cnf

登陆且打开MY.CNF文件,在[mysqld]中加入一行脚本 skip-grant-tables

添加脚本完毕之后,保存退出。

第二、重启MYSQLD生效

/etc/init.d/mysqld res- ( wtart

第三、修改MYSQL重置密码

/, 0 a e m a C husr/bin/mysql

( q a下面的,整个操作过程

[root@localhost ~]# /usr/bin/mysql
Welcome t^ b f r & no the MySQL monitor. Commands end with ; or \g.
Your MyM _ 8 e J 6SQ[ D M & F 9 D l uL connection id is 2
Server versio; ? 4 % Fn: 5.0.95 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights rese/ m A w N W ] [rved.

Oracle is a registered trademark of OraO a , r rcle Corporation and/or its
affiliate~ l ss. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> USE mysql ;
Reading table inforB ~ @ % B hmation for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>P X z A P u UPDATE user SET Password = passwI s W ) e H ( 9ord ( 'itbulu.co+ C # p u s ; - 1m'R x . ) WHERE UserT y x I l P = 'roo1 R Vt' ;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Chanq C L r q V f jged: 3 Warnings: 0

mysql> flush privileges ;* v X 8 f _
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

红色部分是我们需要输入的,尤其是:

UPDATE user SET Passwory R d = password ( 'P g R = e 8 `itbulu.com' ) WHERE User = 'root' ;

这一行,我们应该知道什么意思了吧?就是设置E = 4 z @ . w 8ROOS 7 7T用户的新密码,我们可以改成自己需要设置的_ z /

第四、还原MY.CNF基础设置

同样的到原来第一步中/etc/mj p ; W 6 Uy.cnf文件,然后把s{ l $ W V N = T vkip-grant-tables添加过的去掉后保 = G j ^ M z r v存。

第五9 g ? o : N ]、重启MYSQLD生效

/etc/init.db f Y = ~ W w O 7/mysqld restart

最后,我们再重启MYo 3 _ ~SQLD设置,使得上面的设置生效。

B -稍微简单的方法

/etc/init.d/mysql stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networki, C % S cng &
mysql -u root mysql
mysql> UPDATE user SET Password = password ( 'itbM Z g &ulu.com' ) WHERE0 : ) y K User = 'root' ;
mysql> flush privileges;
mysql> quit
/etcD G D 4 y/init.d/mysql restart

其实也就是把第一种方法简化执行,最好的方法只一行行执行上面脚本,不要直接都复制进去。以免出现错误。

就这样,我们就可以把MYSQL账户中的ROOT用户密码重置完毕,我们任选一种方法都可以实现 O ; !需要的效果。