码迷,mamicode.com
首页 > 数据库 > 详细

mysql修改用户密码

时间:2016-10-12 14:25:14      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:mysql 修改密码

1)命令行的模式

# mysqladmin -u root -p‘redhat12345‘ password ‘zabbix12345‘-S /data/3306/mysql.sock
将密码redhat12345修改为zabbix12345

2)SQL语句修改法

mysql> update mysql.user set password=‘12345‘ where user=‘root‘ and  host=‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+------------+-------------------------------------------+
| user | host       | password                                  |
+------+------------+-------------------------------------------+
| root | localhost  | 12345                                     |
| root | C67-X64-A8 |                                           |
| root | 127.0.0.1  |                                           |
| root | ::1        |                                           |
|      | localhost  |                                           |
|      | C67-X64-A8 |                                           |
| wan  | %          | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| wan  | 10.10.10.% | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| rep  | 10.10.10.% | *2698A63E7F5138951B60F853417ADB4CE2A02D87 |
+------+------------+-------------------------------------------+
9 rows in set (0.00 sec)
说明:我们发现上面显示的结果中,password居然是明文显示,很明显,不可能登陆到数据库
正确的做法:
结合password()函数:
mysql> update mysql.user set password=password(redhat12345) where user=‘root‘ and  host=‘localhost‘;
ERROR 1054 (42S22): Unknown column ‘redhat12345‘ in ‘field list‘
错误原因,字符串应该用引号引起来(可以用单引号或者双引号)

mysql> update mysql.user set password=password(‘redhat12345‘) where user=‘root‘ and  host=‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

登陆进行测试:
[root@mysql-master mysqlback]# mysql -uroot -predhat12345 -S /data/3306/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql>


3)利用set命令来解决(不适合--skip-grant-tables方式修改密码)

mysql> set password=password("redhat12345");
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

注意:

a) 修改密码的时候,必须指定where条件

b) 使用password()函数来加密更改密码


本文出自 “冰冻vs西瓜” 博客,请务必保留此出处http://molewan.blog.51cto.com/287340/1861052

mysql修改用户密码

标签:mysql 修改密码

原文地址:http://molewan.blog.51cto.com/287340/1861052

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!