關於Linux下MySQL修改root密碼時遇到的問題

來源:互聯網
上載者:User

在Linux系統中搭建好LAMP環境之後,我想把自己的一些網站掛在Linux系統中,為了安全起見要設定mysql中root的密碼(預設root密碼為空白)以前用命令mysqladmin -u root -p password bixinnan可以設定成功,可是這次卻出現如下錯誤:

[root@localhost ~]# mysqladmin -u root password bixinnan
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

    如所示:


    這種情況還是第一次遇到,沒辦法就到處找資料。網上很多方法都不行,最後結合多家精髓總結出適合自己的方法如下:

用 service mysqld stop(或者killall mysqld  )命令結束mysql服務進程

mysqld_safe --skip-grant-tables &  啟動安全模式

輸入 mysql -uroot -p 斷行符號進入 (不用密碼)

>use mysql;

> update user set password=PASSWORD("bixinnan")where user="root"; 更改密碼為 bixinnan

> flush privileges; 更新許可權
> quit 退出

service mysqld restart

mysql -uroot -p新密碼進入  如所示:


到這裡linux下mysql修改root密碼基本上就可以了。在學習的過程中我也總結了其他修改密碼方法供大家參考:

方法一

  使用mysqladmi

  mysqladmin -u root -p password bixinnan

  輸入這個命令後,需要輸入root的原密碼,然後root的密碼將改為bixinnan。

  把命令裡的root改為你的使用者名稱,你就可以改你自己的密碼了。

  當然如果你的mysqladmin串連不上mysql server,或者你沒有辦法執行mysqladmin,那麼這種方法就是無效的。

  而且mysqladmin無法把密碼清空。

聯繫我們

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