mysql修改root密码

网上直接的 UPDATE user SET password=PASSWORD("new password") WHERE user='name'; 基本就是坑跌

使用本文方法修改成功!

 

方法一:

(适用于管理员或者有全局权限的用户重设其它用户的密码)
进入命令行模式
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值