Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4161080
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2007-09-04 10:54:38

新手在这个上往往容易范错误,导致不能进入MYSQL,整得非常郁闷。
我来做几个例子相信很快就明白了 。
1、原来的密码是123456
C:\>type mysql5.bat
@echo off
mysql -uroot -p123456 -P3306
正确的修改MYSQL用户密码的格式是:
我们这里用
用户:root(可以换成其他的)
密码:woshiduide
来演示新密码。

C:\>mysqladmin -uroot -p password woshiduide
Enter password: ******
于是修改成功。
注意PASSWORD关键字后面的空格

有好多人是这样修改的:
C:\>mysqladmin -uroot -p password 'woshiduide'
Enter password: ******

C:\>mysqladmin -uroot -p password 'woshiduide'
Enter password: *********
Warning: single quotes were not trimmed from the password by your command
line client, as you might have expected.

而这个时候真正的密码是'woshiduide'

C:\>mysql -uroot -p'woshiduide'
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

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

mysql>

而新手往往这样:
C:\>mysql -uroot -pwoshiduide
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
ES)
所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。

我现在把密码改回去。
C:\>mysqladmin -uroot -p'woshiduide' password 123456

2、还有就是可以直接进入MYSQL,然后修改密码。

mysql> use mysql
Database changed
mysql> update user set PASSWORD = PASSWORD('woshiduide') where USER='root' and H
OST='localhost';
Query OK, 1 row affected (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;

mysql> exit
Bye

C:\>mysql -uroot -pwoshiduide
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

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

mysql>
Query OK, 0 rows affected (0.02 sec)
3、还有一种就是用SET PASSWORD 命令修改:

C:\>mysql5.bat
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)

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

mysql> set password for root@'localhost' = password('woshiduide');
Query OK, 0 rows affected (0.02 sec)

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

mysql> exit
Bye
4、GRANT 也可以,不过这里不介绍。因为涉及到权限的问题。

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

chinaunix网友2011-04-30 09:28:35

谢谢分享 ..

chinaunix网友2008-05-13 18:21:16

楼主实在是太好了,这个问题已经困扰了我好几次了,这次终于彻底解决了. 不过我想问以下楼主,使用第二种方法修改密码时,为什么需要加上 and H OST='localhost'这个条件,然后是flush privileges;如果不添加flush privileges,会出现什么问题? 我看了以下Mysql的API,搞的不是很明白,谢谢楼主的分享.