標籤: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: 0mysql> 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: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)登陸進行測試:[[email protected] mysqlback]# mysql -uroot -predhat12345 -S /data/3306/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 27Server version: 5.5.32-log Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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修改使用者密碼