mysql 忘记root密码怎么办

回复 收藏
如果忘记root密码或其他用户密码,不要急,按下面操作即可。
1. 编辑mysql主配置文件 my.cnf
vim /etc/my.cnf  
在[mysqld]字段下添加参数  skip-grant  
2. 重启数据库服务
service mysqld restart
3. 这样就可以进入数据库不用授权了
mysql -uroot
4. 修改相应用户密码
use mysql;
update user set password=password('your password') where user='root';
flush privileges;
5.  修改/etc/my.cnf 去掉 skip-grant , 重启mysql服务
2010-05-06 11:35 举报
已邀请:
0

赞同来自:

支持楼主,顶你!!!
0

赞同来自:

恩,下面的操作可能更简单,但思路是一样的
bash> service mysqld stop
bash> mysqld --skip-grant-tables &
bash> mysql -u root
mysql> use mysql;
mysql> set password for 'root'@'localhost' = password('hello123');
mysql> flush privileges;
0

赞同来自:

本帖最后由 Bordeaux 于 2012-10-23 14:30 编辑

产品环境执行
bash> /usr/bin/mysql_secure_installation

===
[root@manhh3 ~]# service mysqld start
Initializing MySQL database:  WARNING: The host 'manhh3' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h manhh3 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@manhh3 ~]#
[root@manhh3 ~]#
0

阿铭 管理员

赞同来自:

恩,下面的操作可能更简单,但思路是一样的
bash> service mysqld stop
bash> mysqld --skip-grant-tables &
bash> mysql -u root
mysql> use mysql;
mysql> set password for 'root'@'localhost' = password('hello123');
mysql> flush privileges;
0

麦小秋

赞同来自:

终于让我找到了  回去试试
0

yang.lin.801109

赞同来自:

收藏,颇具一定实力
0

a516373577

赞同来自:

学习,学习,学习
0

657402624

赞同来自:

学习了
0

657402624

赞同来自:

学习了
0

xiaotuanyu120

赞同来自:

好方法
0

xiaotuanyu120

赞同来自:

铭哥,其实update的时候,多加一个条件where host = ‘localhost’ 会更精准一些
0

cherrypi

赞同来自:

学习了。
0

lyhabc

赞同来自:

收藏了
0

struggling

赞同来自:

不需要--skip-networking吗?    那样会有风险吧
0

IceCry

赞同来自:

学习了,之前还真心没想过这个问题 :)
0

Voyage.W

赞同来自:

有用!

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: