MySQL資料庫登入密碼管理

來源:互聯網
上載者:User

標籤:mysql資料庫 密碼 忘記密碼 資料庫丟失密碼

    mysql資料庫安裝完成預設管理員的登入密碼為空白,因此可以無需輸入密碼直接登入資料庫,這樣是不安全的,以下文章簡單介紹如何設定管理員登入資料庫的密碼和如何修改登入密碼,以及忘記登入密碼如何處理。

一、環境介紹

 作業系統:CentOS 6.5

 資料庫版本:MySQL 5.5.32

 主機名稱:mysql-singleton

二、資料庫密碼管理

 1、設定資料庫初始密碼

 [[email protected] ~]# mysqladmin -uoldcat password "123456"

 2、命令列修改資料庫登入密碼

 1)linux命令列修改mysql資料庫密碼

[[email protected] ~]# mysqladmin -uoldcat -p123456 password "oldcat123"

 2)mysql命令列修改密碼

mysql> select user,host,password from mysql.user;+--------+------+-------------------------------------------+| user  | host| password                   |+--------+------+-------------------------------------------+| oldcat| %   |*41A67287D4BD4E7159DD624068D666ADC8917813 |+--------+------+-------------------------------------------+1 row in set (0.00 sec)mysql> update mysql.user set password=password("123456") where user="oldcat";Query OK, 1 row affected (0.00 sec)Rows matched: 1  Changed: 1  Warnings: 0註:通過password函數為密碼明文加密mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)註:修改密碼執行flush privileges重新整理緩衝,使其立即失效也可以直接通過set命令修改當前登入使用者的密碼mysql> set password=password("oldcat123");Query OK, 0 rows affected (0.00 sec)

 3)如果忘記資料庫密碼,則通過忽略授權表的方法啟動資料庫並更新資料庫登入密碼

a、首先停止mysql資料庫服務[[email protected] ~]# /etc/init.d/mysqld stopShutting down MySQL. SUCCESS!b、忽略授權表啟動mysql資料庫服務[[email protected] ~]# mysqld_safe --skip-grant-tables --user=mysql &[1] 27447[[email protected] ~]# 160308 23:03:44 mysqld_safe Logging to ‘/application/mysql-5.5.32/data/mysql-singleton.err‘.160308 23:03:44 mysqld_safe Starting mysqld daemon with databases from /application/mysql-5.5.32/data註:本例使用的mysql資料庫單一實例,如果為多執行個體需要通過--defaults-file指定my.cnf目錄c、無需輸入密碼登入資料庫[[email protected] ~]# mysql -uoldcatWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.32 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> d、通過update命令修改密碼(通過忽略授權表的方式啟動資料庫是不允許使用set命令更新密碼)mysql> update mysql.user set password=password("123456") where user="oldcat";Query OK, 1 row affected (0.01 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)e、重新啟動mysql資料庫服務,並輸入密碼形式登入資料庫[[email protected] ~]# /etc/init.d/mysqld startStarting MySQL.. SUCCESS! [[email protected] ~]# ss -lntup|grep 330tcp    LISTEN     0      50                     *:3306                  *:*      users:(("mysqld",28000,10))[[email protected] ~]# mysql -uoldcat -p123456Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.32 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>


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.