ubuntu下mysql的'Access denied for user 'root&a

來源:互聯網
上載者:User

問題現象:

我的環境是xubuntu 12.10下apt-get安裝mysql,登陸無法登陸,報錯資訊這樣描述:在用命令(sudo apt-get install mysql-server mysql-client)安裝完.mysql服務即開始運行了.此時需要修改root密碼,但經常會出現這麼一種情況.'Access denied for user 'root'@'localhost' (using password: YES)' 或者其他致使無法登入mysql的情況。

 

解決方案:
1.開啟/etc/mysql/debian.cnf檔案,裡面儲存了相關的密碼,我的檔案資訊如下

  /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost


socket = /var/run/mysqld/mysqld.sock


[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = 6x1XG2B5p75WtFV2
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

在[client]段有user=以及password=這兩行,這就是通過apt-get安裝mysql,系統給我們設定的mysql登入名稱和密碼


2. 輸入命令:

mysql -udebian-sys-maint -p

debian-sys- maint即debian.cnf中user=後面的內容.斷行符號後會提示輸入密碼,此時把password=後面的內容複寫粘貼後斷行符號即可進行mysql 控制台

 

3.進入控制台後.按以下步驟進行:

=PASSWORD() where user=

此時可以輸入quit;退出後用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.