西安做网站_西安网站建设公司_西安网页制作_西安网页设计_西安网站制作设计公司

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8280|回复: 0

MYSQL修改密码的几种方式(提示错误:No Database Selected)

[复制链接]
发表于 2013-1-25 17:37:20 | 显示全部楼层 |阅读模式
其实手册里有的,只是现在这个年代,似乎大家都不看手册啦,而是在QQ或者群里又或者论坛发问
   为什么不用搜索?

方法一:
(适用于管理员或者有全局权限的用户重设其它用户的密码)
进入命令行模式
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='name';
  mysql> FLUSH PRIVILEGES;
  mysql> QUIT
方法二:
(应用同上,只是方法不同)
mysql -u root mysql
  mysql> SET PASSWORD FOR name=PASSWORD('new password');
  mysql> QUIT
(以上两种方法我不常用,如果是管理员,我会用其它如phpmyadmin或者MYSQL-front 等工具来管理用户权限,比较直观又方便)
最后必杀技:
mysqladmin -u root "old password" "new password"
解:以上有name的,请用你的用户名来替代.有new password请输入你想要设置的密码.

提示错误:No Database Selected后如何修改

C:\mysql\bin>mysql
-uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.15-nt

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

mysql> update user set password=password('root') where user='root';
ERROR 1046: No Database Selected
mysql> use mysql
Database changed
mysql> select host,user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         |      |
| %         | root |
| localhost |      |
| localhost | root |
+-----------+------+
4 rows in set (0.02 sec)

mysql> update user set password=password('root') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

mysql> quit
Bye

C:\mysql\bin>mysql  -uroot
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

C:\mysql\bin>mysql  -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6 to server version: 4.0.15-nt

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

mysql> quit
Bye

西安网站建设 | 西安做网站 —— 剑锋所指 所向披靡!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西安网站建设

GMT+8, 2024-3-28 16:27 , Processed in 0.041202 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表