Ubuntu安裝MySQL資料庫

來源:互聯網
上載者:User

標籤:apt   gmail   使用   dev   mct   mysq   tar   select   使用者登入   

Ubuntu的上安裝的MySQL非常簡單只需要幾條命令就可以完成。
  sudo apt-get install mysql-server(卸載是sudo aptitude purge mysql-server但是要安裝sudo apt-get install aptitude才能用)


Ubuntu 16.04安裝使用MySQL

MySQL是流行的資料庫系統,下面記錄了在Ubuntu 16.04上安裝MySQL步驟。

如果你使用的是Ubuntu 16.04以前的版本,可以看這裡:Ubuntu 14.04/15.10升級到Ubuntu 16.04 LTS。


安裝前先更新軟體包列表:


$ sudo apt update
1
$ sudo apt update
在Ubuntu 16.04上安裝MySQL:


$ sudo apt install mysql-server mysql-client
1
$ sudo apt install mysql-server mysql-client
在安裝過程中需要你輸入MySQL 管理使用者(root)密碼
運行MySQL初始化安全指令碼:

$ sudo mysql_secure_installation
mysql_secure_installation指令碼設定的東西:更改root密碼、移除MySQL的匿名使用者、禁止root遠程登入、刪除test資料庫。使用上面的這些選項可以提高MySQL的安全。
MySQL資料庫基本使用

使用root使用者登入:


$ mysql -u root -p

輸入root密碼:
mysql -h localhost -u root -p
-u 表示選擇登陸的使用者名稱
-p 表示登陸的使用者密碼
-h 登入主機名稱

建立MySQL資料庫和使用者:


mysql> create database snailblog;

上面命令建立了一個名為snailblog的資料庫。

建立使用者,並使用snailblog資料庫:


mysql> grant all on snailblog.* to ‘man_user‘ identified by ‘test1234‘;
使用新使用者登入:


$ mysql -u man_user -p snailblog

Screen Shot 2016-04-02 at 09.25.53

建立表:

mysql> CREATE TABLE user (id INT, name VARCHAR(20), email VARCHAR(20));
插入記錄:

mysql> INSERT INTO user (id,name,email) VALUES(1,"bar","[email protected]");
mysql> INSERT INTO user (id,name,email) VALUES(2,"foo","[email protected]");
mysql> INSERT INTO user (id,name,email) VALUES(3,"cat","[email protected]");
簡單查詢:

mysql> SELECT * FROM user;
Screen Shot 2016-04-02 at 09.31.07

退出MySQL命令列:


mysql> quit
Bye
1

停止MySQL資料庫服務:


$ sudo systemctl stop mysql.service

啟動MySQL資料庫服務:


$ sudo systemctl start mysql.service

重啟MySQL資料庫服務:


$ sudo systemctl restart mysql.service
查看MySQL運行狀態:

$ sudo systemctl status mysql.service

MySQL的設定檔:


$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
MySQL 5.6文檔:http://dev.mysql.com/doc/refman/5.6/en/

Ubuntu安裝MySQL資料庫

聯繫我們

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