誤刪除mysql中的所用使用者,如何重新設定root帳號和密碼

來源:互聯網
上載者:User

標籤:root使用者誤刪   mysql   使用者添加   

在練習mysql語句的時候,使用delete將資料庫中的所有使用者刪除了,其中也包括root使用者。並進行了flush privileges;這時候發現重新登入mysql已經不能正常登陸。對此我們要重新設定root帳號和root密碼。具體操作步驟如下:

刪除使用者操作:  

mysql> delete frommysql.user;  刪除所有使用者mysql> flushprivileges;

首先斷掉與資料庫相關聯的所有連結,防止咋資料庫重啟的時候資料的丟失。

[[email protected] ~]# service mysqld stop

修改資料庫設定檔

[[email protected] ~]# vim /etc/my.cnf

在設定檔中的[mysql]下的內容

在[mysql]

下一行中添加“skip-grant-tables”

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/87/FC/wKioL1fnJ9rTsEHnAAAo_-skRVE661.png-wh_500x0-wm_3-wmp_4-s_2194652098.png" title="if.png" alt="wKioL1fnJ9rTsEHnAAAo_-skRVE661.png-wh_50" />

儲存並退出,重啟mysql資料庫

[[email protected]]# mysql

mysql> insertinto mysql.user (host, user, password,sll_cipher,x509_issuer,x509_subjec) values (‘localhost‘, ‘root‘,password(‘123456‘),’’,’’);


退出資料庫,再將mysql.cnf設定檔變更,刪除剛才新添加的行即可。重新啟動資料庫即可。

[[email protected] ~]# service mysqld restart

即可完成對mysqlroot使用者的添加!

第二種方式不修改mysql的設定檔;

service mysqld stop        //停止mysql資料庫服務mysqld_safe--skip-grant-tables --skip-networking


另外終端

Mysqlmysql> insertinto mysql.user (host, user, password,sll_cipher,x509_issuer,x509_subjec) values (‘localhost‘, ‘root‘,password(‘123456‘),’’,’’);


即可完成對資料庫root使用者的添加!


本文出自 “心空瀰漫” 部落格,請務必保留此出處http://aiyouwei.blog.51cto.com/11705634/1856266

誤刪除mysql中的所用使用者,如何重新設定root帳號和密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.