mysql的root密码重置

[root@gz1 ~]# mysqladmin -uroot password '123456'    给MySQL设置一个密码
[root@gz1 ~]# mysql -uroot -p123456    本地登录MySQL

假如我们现在MySQL密码已忘记,现在进行重置。

[root@gz1 ~]# vim /etc/my.cnf   编辑配置文件
skip-grant  加入这个保存退出(不授权直接可以登录)
[root@gz1 ~]# /etc/init.d/mysqld restart   重启一下MySQL
Shutting down MySQL..... SUCCESS!
Starting MySQL. SUCCESS!
[root@gz2 ~]# mysql -uroot   直接就可以登录了
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
mysql> use mysql                             //使用mysql库
mysql> update user set password=password('654321') where user='root'; //更新表(修改密码)
mysql>quit

然后找到/etc/my.cnf配置文件,删除之前的skip-grant命令,保存退出后重启MySQL服务

[root@gz1 ~]# /etc/init.d/mysqld restart
[root@gz2 ~]# mysql -uroot -p654321    更改密码生效,重新登入
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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



你可能感兴趣的:(mysql,密码,welcome)