Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3095583
  • 博文数量: 797
  • 博客积分: 10134
  • 博客等级: 上将
  • 技术积分: 9335
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 22:57
个人简介

1

文章分类

全部博文(797)

文章存档

2022年(1)

2021年(2)

2017年(2)

2016年(1)

2015年(4)

2014年(1)

2013年(6)

2012年(6)

2011年(10)

2010年(26)

2009年(63)

2008年(61)

2007年(51)

2006年(563)

我的朋友

分类: LINUX

2006-07-24 16:44:03

如何恢复MYSQL的ROOT口令
作者:不详 (2001-05-16 15:41:43)
如果你忘记了你的MYSQL的root口令的话,你可以通过下面的过程恢复。
  1. 向mysqld server 发送kill命令关掉mysqld server(不是 kill -9),存放进程ID的文件通常在MYSQL的数据库所在的目录中。
      kill `cat /mysql-data-directory/hostname.pid`
     你必须是UNIX的root用户或者是你所运行的SERVER上的同等用户,才能执行这个操作。
  2. 使用`--skip-grant-tables' 参数来启动 mysqld。
  3. 使用`mysql -h hostname mysql'命令登录到mysqld server ,用grant命令改变口令。你也可以这样做:`mysqladmin -h hostname -u user password 'new password''。
(其实也可以用use mysql; update user set password =password('yourpass') where user='root' 来做到。)
  4. 载入权限表: `mysqladmin -h hostname flush-privileges' ,或者使用 SQL 命令`FLUSH PRIVILEGES'。(当然,在这里,你也可以重启mysqld。)


试试到mysql\bin目录下,使用mysqladmin -u root  password "新密码";

Yjd测试:

1.killall mysqld     //杀掉mysqld服务

2.mysqld_safe --user=mysql --skip-grant-tables

3.使用第一个方法没成功:

[root@localhost ~]# mysqladmin -hlocalhost -uroot password 'yjd'

  尝试第二种》

[root@localhost ~]# mysql -umysql   //输入命令出现如下


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.11Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>use mysql; 回车出现如下:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed     //不管继续

mysql> update user set password =password('yjd') where user='root';

//输入命令修改root密码为yjd出现如下

        
Database changed
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> exit          //看到ok应该没问题了^_^,退出。
Bye

[root@localhost ~]# service mysqld restart //重启mysqld服务

StoppingMySQL:                                      [  OK  ]
Starting MySQL:                                     [  OK  ]
[root@localhost ~]#
[root@localhost ~]# mysql -uroot -p    //登入看看密码为yjd
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.11

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>                                  //ok搞定。


 



 

阅读(1442) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~