您好,欢迎访问一九零五行业门户网

CentOS系统重置MySQL数据库密码

学习centos linux的时候经常会忘记各种密码,本文主要说明在使用centos的过程中,忘记mysql数据库密码的解决办法。 第一步:通过如下代码,停止mysql服务器的运行 01 02 [root@centos5 ~]# service mysqld stop stopping mysql: [ ok ] 第二步:使用 “–ski
学习centos linux的时候经常会忘记各种密码,本文主要说明在使用centos的过程中,忘记mysql数据库密码的解决办法。
第一步:通过如下代码,停止mysql服务器的运行
01
02
[root@centos5 ~]# service mysqld stop
stopping mysql:                                            [  ok  ]
第二步:使用 “–skip-grant-tables”参数重新启动mysql
01
02
03
[root@centos5 ~]# mysqld_safe --skip-grant-tables &
[1] 23810
[root@centos5 ~]# starting mysqld daemon withdatabases from/var/lib/mysql
第三步:用帐号登录mysql
01
02
03
04
05
[root@centos5 ~]# mysql -u root
welcometothe mysql monitor.  commands endwith ; or\g.
your mysql connectionid is1
server version: 5.0.77 source distribution
type'help;'or '\h' for help. type '\c'to clear the buffer.
第四步:改变用户数据库表
01
02
03
04
mysql> use mysql
readingtableinformation forcompletion oftable and column names
you can turn offthis feature toget a quicker startup with-a
databasechanged
第五步:修改密码,记得密码要用password()函数进行加密,一定不要忘记!不然,
01
02
03
mysql>updateuser set password=password('admin123')whereuser='root';
query ok, 1 row affected (0.04 sec)
rowsmatched: 1  changed: 1  warnings: 0
第六步:刷新权限表
01
02
03
04
mysql> flush previleges;
error 1064 (42000): you have an error inyour sql syntax; checkthe manual that corresponds toyour mysql server version forthe rightsyntax touse near 'previleges'at line 1
mysql> flush privileges;
query ok, 0 rowsaffected (0.00 sec)
第七步:退出mysql
01
02
mysql> quit
bye
第八步:对mysql进行重启
01
02
03
04
05
06
[root@centos5 ~]# service mysqld restart;
stopping server frompid file /var/run/mysqld/mysqld.pid
100421 13:44:03  mysqld ended
stopping mysql:                                            [  ok  ]
starting mysql:                                            [  ok  ]
[1]+  done                    mysqld_safe --skip-grant-tables
第九步:用更改过的密码重新登录即可。
01
02
03
04
05
06
07
08
09
[root@centos5 ~]# mysql -u root -p
enterpassword: admin123
welcometothe mysql monitor.  commands endwith ; or\g.
your mysql connectionid is2
server version: 5.0.77 source distribution
type'help;'or '\h' for help. type '\c'to clear the buffer.
mysql> quit
bye
[root@centos5 ~]#
其它类似信息

推荐信息