Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2766560
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: Mysql/postgreSQL

2009-09-11 09:19:08

Linux下忘记mysql密码
想登录mysql数库, 突然记不得mysql下root用户的密码了。
下面是处理过程
1:关闭mysql(一定不要用kill -9 pid或pkill mysql之类的命令, 用这种命令尽管会强制关闭数据库, 但使得数据库有很多的碎片,容易使得数据crash(我图方便就用了两次,尽管我知道不能用pkill,数据库就crash了。最好用service mysql stop关闭它)
2:测试是否真正关闭
3:开启mysql用--skip-grant-tables 项,即可不提示输入密码
4:mysql -u root -p 通过空密码进入mysql,
5:选择mysql库下的user表,修改root用户对应当密码
6:flush privileges 刷新缓冲区
7:退出mysql,重新登陆测试(此时密码已经生效,不需要重启mysql)
以下是我的处理过程!

[root@localhost ~]# service mysql stop   ##究竟是mysql还是mysqld要看你在/etc/rc.d/init.d下到底是mysql还是mysqld
[root@localhost ~]# netstat -antl | grep 3306
[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
[1] 3701
[root@localhost ~]# Starting mysqld daemon with databases from /usr/local/mysql/data

[root@localhost ~]# netstat -antl | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.83 MySQL Community Server (GPL)

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

mysql> update user set password=password('root') where user='root';
ERROR 1046 (3D000): No database selected
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('root') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.83 MySQL Community Server (GPL)

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


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