1)命令行的模式
1
2
|
# mysqladmin -u root -p'redhat12345' password 'zabbix12345'-S /data/3306/mysql.sock
将密码redhat12345修改为zabbix12345
|
2)SQL语句修改法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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方式修改密码)
1
2
3
4
|
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西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1861052,如需转载请自行联系原作者