Ubuntu下MySQL資料庫的安裝使用

來源:互聯網
上載者:User

首先: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檔案,裡面儲存了相關的密碼.
sudo gedit /etc/mysql/debian.cnf
在[client]段有user=以及password=這兩行,此即我們需要的東西

2. 輸入命令:mysql -udebian-sys-maint -p
debian-sys-maint即debian.cnf中user=後面的內容.斷行符號後會提示輸入密碼,此時把password=後面的內容複寫粘貼後斷行符號即可進行mysql控制台(一般不要照打,容易出錯,複製即可)

3.進入控制台後.按以下步驟進行:
use mysql;
update user set password=PASSWORD('新密碼') where user='root';
FLUSH PRIVILEGES;
此時可以輸入quit;退出後用root帳號登入,也可以繼續其他動作

卸載mysql:sudo apt-get remove mysql-server mysql-client
sudo apt-get autoremove

相關文章

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.