如何在MySQL中更改root用户的密码? [英] How do I change the password of the root user in MySQL?
本文介绍了如何在MySQL中更改root用户的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很早就忘记了我的其中一个盒子上root用户的密码.有没有一种方法可以更改它而无需登录实例,还是必须重新安装?
I have long since forgotten the password for the root user on one of my boxes. Is there a way I can change it without having to log in to the instance, or will I have to reinstall?
推荐答案
步骤1
停止数据库:
shell> /etc/init.d/mysql stop
第2步
重新启动数据库
- 没有密码加强
- 没有连接到网络
只能通过其sock文件"/var/lib/mysql/mysql.sock"来访问数据库.
Access to database is only possible through it's sock file '/var/lib/mysql/mysql.sock'.
shell> mysqld --user=mysql --pid-file=/var/lib/mysql/mysqld.pid \
--socket=/var/lib/mysql/mysql.sock --datadir=/var/lib/mysql \
--skip-grant-tables --skip-networking &
第3步
连接到数据库并更改密码:
Connect to the database and change password:
shell> mysql --database mysql --socket=/var/lib/mysql/mysql.sock
如果需要,请显示所有用户:
If you want to, show all users:
mysql> select User, password from user;
设置新密码:
mysql> update user set password=password('NEW PASS') WHERE User='USERNAME';
离开数据库连接:
mysql> exit
第4步
正常"重启数据库服务器.
Restart database server "normally".
shell> kill `cat /var/lib/mysql/mysqld.pid`
shell> /etc/init.d/mysql start
这篇关于如何在MySQL中更改root用户的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文