mysql修改使用者密碼

來源:互聯網
上載者:User

標籤: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修改使用者密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.