一、預備知識
1.安裝mysql
2.開啟mysql服務#安裝 mysql 服務端、核心程式
sudo apt-get install mysql-server
#安裝 mysql 客戶端
sudo apt-get install mysql-client
$sudo service mysql start
3.以root身份登入4.檢視資料庫# 使用 root 使用者登入,實驗樓環境的密碼為空,直接回車就可以登入
$mysql -u root
$show databases
5.切換資料庫use 《資料庫名》
6.檢視資料庫中的表$show tables
7.quit or exit 退出資料庫
8.刪除乙個資料庫
drop database mysql_shiyan;
9.刪除乙個表drop table mysql_shiyan;
10.執行某個在外部的資料庫source /home/shiyanlou/desktop/sql3/mysql-03-01.sql
二、建立新的資料庫對應的資料型別有:create table 表的名字 (列名a 資料型別(資料長度),列名b 資料型別(資料長度),列名c 資料型別(資料長度));
例子:create table employee (id int(10),name char(20),phone int(12));
資料型別
大小(位元組)
用途格式
int4
整數float
4單精度浮點數
double
8雙精度浮點數
enum
單選,比如性別
enum(『a』,』b』,』c』)
set多選 set(『1』,』2』,』3』)
date3日期
yyyy-mm-dd
time
3時間點或持續時間
hh:mm:ss
year
1年份值
yyyy
char
0~255
定長字串
varchar
0~255
變長字串
text
0~65535
長文字資料
2.1 插入資料
三、約束分類insert into 表的名字(列名a,列名b,列名c) values(值1,值2,值3);
例子:insert into employee(id,name,phone) values(01,'tom',110110110);
select * from employee;#檢視是否插入到了表中
約束型別
主鍵預設值
唯一外來鍵
非空關鍵字
primary key
default
unique
foreign key
not null
三、查詢語句
寫法:
select 要查詢的列名 from 表名字 where 限制條件;
例子:
select name,age from employee where age>25;
select name,age,phone from employee where name=』mary』;
「and」與「or」的應用:
#篩選出 age 小於 25,或 age 大於 30
select name,age from employee where age<25 or age>30;
#篩選出 age 大於 25,且 age 小於 30
select name,age from employee where age>25 and age<30;
#篩選出 age 大於 25,且 age 小於 30
select name,age from employee where age betwenn 25 and 30;
select name,age,phone,in_dpt from employee where in_dpt in ('dpt3','dpt4');
實驗樓Linux實驗(一)
在每個使用者的 home 目錄中有乙個 shell 每次啟動時會預設執行乙個配置指令碼,以初始化環境,包括新增一些使用者自定義環境變數等等。zsh 的配置檔案是 zshrc,相應 bash 的配置檔案為 bashrc 它們在 etc 下還都有乙個或多個全域性的配置檔案,不過我們一般只修改使用者目錄下...
Numpy實驗樓報告
最近入門machine learning,再看peter harrington的 machine learning in action 發現numpy真的是python語言裡非常重要的乙個庫,尤其在機器學習演算法的程式設計中有廣泛的應用。於是筆者到 實驗樓 上去學習了一波,下面吧連線 numpy的介...
實驗樓 玩轉函式
請在 home shiyanlou code寫出乙個minutestohours.py指令碼檔案,實現乙個函式hours 將使用者輸入的分鐘數轉化為小時數和分鐘數,並要求小時數盡量大。將結果以xx h,xx m的形式列印出來。注意列印格式中的空格 usr bin env python3 import...