积分 753276
经验 757270
突出贡献 突出贡献
热心标兵 热心标兵
论坛元老 论坛元老
智慧达人 智慧达人

What If You Forget Mysql Root Password

发布于: 2007/11/29  10:40 pm 更新于: 2008/01/23, 1:09 am

If you have set a root password, but forgot what it was, you can set a new password with the following procedure:
1. Take down the mysqld server by sending a kill (not kill-9) to the mysqld server. The pid is stored in a `.pid' file, which is normally in the MySQL database directory:
shell> kill `cat /mysql-data-directory/hostname.pid`
You must be either the Unix root user or the same user mysqld runs as to do this.
2. Restart mysqld with the --skip-grant-tables option.
3. Set a new password with the mysqladmin password command:
shell> mysqladmin -u root password 'mynewpassword'
4. Now you can either stop mysqld and restart it normally, or just load the privilege tables with:
shell> mysqladmin -h hostname flush-privileges
5. After this, you should be able to connect using the new password.
Alternatively, you can set the new password using the mysql client:
1. Take down and restart mysqld with the --skip-grant-tables option as described above.
2. Connect to the mysqld server with:
shell> mysql -u root mysql
3. Issue the following commands in the mysql client:
mysql> UPDATE user SET Password=PASSWORD('mynewpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;
4. After this, you should be able to connect using the new password.
5. You can now stop mysqld and restart it normally.

test by zach
_________________
洛杉矶华人资讯网-华人资讯,一网打尽
返回页首
举报
积分 753276
经验 757270
突出贡献 突出贡献
热心标兵 热心标兵
论坛元老 论坛元老
智慧达人 智慧达人

发布于: 2008/01/23  1:09 am

1. Kill the server (kill -9 mysqld, you will probably need to log in as OS
user 'root').
2. Start the server with the option skip-grant-tables, e. g.
mysqld --skip-grant-tables.
3. Connect to the server using MySQL Monitor, the command line tool: shell>
mysql (You can connect without username/password.)
4. On the SQL command line, do: GRANT ALL ON *.* TO 'superuser'@'localhost'
IDENTIFIED BY 'iwillremember' WITH GRANT OPTION;
5. Exit MySQL Monitor.
6. On the shell, do: mysqladmin -usuperuser -piwillremember shutdown
7. On the shell, do: mysqld (to start the server again)
Now, this new 'superuser' can create accounts for regular users.

_________________
洛杉矶华人资讯网-华人资讯,一网打尽
点评这篇文章
点评这篇文章
 
1 2 3 4 5
1个人参与评分
Advertiser Disclosure
最新商家点评
ChineseInLA总共有76646条点评, 59229次评分
洛杉矶格力空调总代理
Review by 6201144 at 09/06/25
请问你们公司地址 谢谢
天一空调、制冷设备安装及维修
Review by 9004A m y at 09/06/25
今天这个师傅到我家把空调修好了,我非常的高兴,因为我找了好几个师傅都没有修好,这个师傅经验丰富,把我家的空调修好了...
专业驾校教练—郑教练(女教练)超耐心
Review by 2379cj6bj6 at 09/06/25
老师教得很详细也很有耐心!