系統:ubuntu17.04
數據庫主要分文檔型和服務型兩類:
文檔型:如sqlite3 (17.04自帶/usr/bin/sqlite3)就是一個文件,應用在移動端如手機,pad,家電等
服務型:如mysql有服務端(存儲數據)和客戶端
mysql數據庫是關系型數據庫,采用E-R模型即實體-聯系(或關系)模型
安裝:
sudo apt install mysql-server,需要設置密碼:xxx
sudo apt install mysql-client
sudo apt install libmysqlclient-dev
lyb@lyb:~$ sudo netstat -tap |grep mysql
tcp0 0 localhost:mysql *:* LISTEN 5167/mysqld
成功安裝
登錄:
l@l:~$ mysql -uroot -pxxx
mysql: [Warning] Using a password on the command lineinterfacecan be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis 5Server version:5.7.20-0ubuntu0.16.04.1(Ubuntu)
Copyright (c)2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracleis 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>show databases; #初始有四個數據庫+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.16sec)
創建用戶并授權:
mysql> create user 'l'@'%' identified by '123';
Query OK,0 rows affected (0.09sec)
mysql> select user,host fromuser;+---------------+-----------+
| user | host |
+---------------+-----------+
| l | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00sec)
mysql> grant select on study.* to 'l'@'%';
desc ?user; #顯示其中user表的結構,如下:
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
注:字段創建要有數據類型,長度;Null是否為空,NO表示不能為空;PRI表示主鍵,一般是一個,本表前兩個是聯合主鍵
select ?字段 ?from ?表
exit; #從mysql數據庫退出
ps -ef |grep mysql #在命令行從所有進程篩選mysql