今天在Ubuntu 14.04下安裝MySQL,原本是去官網下載安裝包來安裝的,但是安裝以後卻不能用,估計是要配置吧,在網上搜了不少的資料,結果仍是失敗。因此只好在軟件源中安裝,這樣就省去不少沒必要要的麻煩了。mysql
www.linuxidc.com@linuxidc :~$ sudo apt-get install mysql-server
[sudo] password for linuxidc:linux
執行該命令後,系統還會自動安裝其它的一些軟件,在安裝過程當中會提示輸入mysql的登入密碼。sql
使用Tab鍵選擇肯定數據庫
上圖,要輸入兩次密碼,我這裏就輸入v,測試用嗎。簡單點,記住,後面要用到。
若是系統版本不同,提示的方式可能不同,不過整體來講都差很少。安裝好後,執行命令ubuntu
www.linuxidc.com@linuxidc :~$ mysql
ERROR 1045 (28000): Access denied for user 'linuxidc'@'localhost' (using password: NO)
www.linuxidc.com@linuxidc :~$測試
結果出現錯誤,Google了半天,結果愈來愈沒耐心,這時候翻了翻本身買的書籍,輸入了下面的命令spa
www.linuxidc.com@linuxidc :~$ mysql -uroot -pv.net
其中第一個mysql是命令,-uroot是指定用戶爲root,-pv是輸入登入密碼,v是密碼,若是你設置的密碼是別的,就換成本身安裝時設置的密碼,切記密碼和-p之間不要有空格,否則會失敗的。下面是我成功登入後,查看當前全部存在的數據庫。server
linuxidc@ubuntu :~$ mysql -uroot -pv
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)get
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>