標籤

2016年10月8日 星期六

MySQL 超新手入門 (1) - (20)
                      張益裕

Date: 20161008
Version: 1

這是學習MySQL的網路課程,共20課,我會把每一課相關的指令列出,方便我以後要進行複習。

MySQL 超新手入門(1)重新開始

介紹MySQL和database的概念

MySQL 超新手入門(2)資料庫概論與 MySQL 安裝

1. 儲存與管理資料
1.1 資料庫管理系統與資料庫伺服器
1.2 資料庫
2. SQL介紹
3. MySQL Workbench
4. 下載與安裝MySQL資料庫
5. 安裝範例資料庫

MySQL 超新手入門(3)SELECT 基礎查詢

1 查詢資料前的基本概念
1.1 表格、紀錄與欄位
2 查詢敘述
select, from, where, group by, having, order by, limit
2.1 指定使用中的資料庫
2.2 只有SELECT
2.3 指定欄位與表格
select * from
2.4 指定需要的欄位
2.5 數學運算
2.6 別名
as
3 條件查詢
3.1 比較運算子
=, <=>, !=, <>, <, <=, >, >=
3.2 邏輯運算子
NOT, &&, AND, ||, OR, XOR
3.3 其它條件運算子
between and, in, is, is not, like
3.4 NULL值的判斷
3.5 字串樣式
%, _
4 排序
5 限制查詢
5.1 指定回傳紀錄數量
5.2 排除重複紀錄

MySQL 超新手入門(4)運算式與函式

1 值與運算式
1.1 數值
1.2 字串值
SET sql_mode = 'PIPES_AS_CONCAT'
1.3 日期與時間值
1.4 NULL值
2 函式
SET sql_mode=’IGNORE_SPACE’
datediff
2.1 字串函式
lower, upper, lpad, rpad, ltrim, rtrim, trim, repeat, replace
left, right, substring
concat, concat_ws
length, char_length, locate
2.2 數學函式
round, ceil, ceiling, floor, truncate
pi, pow, rand, sqrt
2.3 日期時間函式
curdate, crutime, year, month, day, monthname, dayname, dayofweek, dayofyear, quarter, extract, hour, minute, second
adddate, addtime, subdate, subtime, datediff
2.4 流程控制函式
if, case, when then, else,
2.5 其它函式
ifnull, isnull
3 群組查詢
3.1 群組函式
max, min, sum, avg, count, distinct
3.2 GROUP_CONCAT函式
3.3 GROUP BY與HAVING子句
asc, desc, with rollup
SET sql_mode = 'ONLY_FULL_GROUP_BY'

MySQL 超新手入門(5)JOIN 與 UNION 查詢

1 使用多個表格
2 Inner Join
2.1 使用結合條件
2.2 指定表格名稱
2.3 表格別名
2.4 使用「INNER JOIN」
join on/using
3 Outer Join
3.1 LEFT OUTER JOIN
3.2 RIGHT OUTER JOIN
4 合併查詢
union

MySQL 超新手入門(6)CRUD 與資料維護

1 取得表格資訊
1.1 DESCRIBE指令
1.2 欄位順序
2 新增
2.1 基礎新增敘述
insert values/set
2.2 同時新增多筆紀錄
2.3 索引值
ignore
2.4 索引值與ON DUPLICATE KEY UPDATE
update
2.5 「REPLACE」敘述
replace
3 修改
update
3.1 搭配「IGNORE」
3.2 搭配「ORDER BY」與「LIMIT」
4 刪除
4.1 「DELETE」敘述
4.2 「TRUNCATE」敘述

MySQL 超新手入門(7)字元集與資料庫

1 Character Set與Collation
1.1 Character Set
SHOW CHARACTER SET
1.2 COLLATION
SHOW COLLATION
2 資料庫
SHOW VARIABLES LIKE ‘datadir’
2.1 建立資料庫
create database if not exits
2.2 修改資料庫
alter database
2.3 刪除資料庫
drop database if exits
2.4 取得資料庫資訊
show
information_schema

MySQL 超新手入門(8)儲存引擎與資料型態

1 表格與儲存引擎
1.1 MyISAM
1.2 InnoDB
1.3 MEMORY
1.4 儲存引擎與作業系統
2 欄位資料型態
2.1 數值
tinyint, smallint, mediumint, int, bigint
float, double, decimal
zerofill, unsigned
2.2 位元
2.3 字串
char, varchar, tinytext, text, mediumtext, longtext
length
binary, varbinary, tinyblob, blob, mediumblob, longblob
2.4 列舉與集合
enum, set
2.5 日期與時間
date, time, datetime, year, timestamp
global, session

MySQL 超新手入門(9)表格與索引

1 建立表格
create table
1.1 表格屬性
engine, charcter set, collate
1.2 字串欄位屬性
1.3 數值欄位屬性
unsigned, zerofill, auto_increment
1.4 通用欄位屬性
null, not null, default
1.5 TIMESTAMP欄位型態與預設值
on update, default current_timestamp
1.6 使用其它表格建立一個新表格
1.7 建立暫存表格
create temporary
2 修改表格
alter table
2.1 增加欄位
add
2.2 修改欄位
change, modify
2.3 刪除欄位
drop
2.4 修改表格名稱
alter table .. rename .., rename table .. to ..
3 刪除表格
drop table
4 索引介紹
primary key, unique index, non-unique index
5 建立索引
5.1 在建立表格的時候建立索引
5.2 在修改表格的時候建立索引
5.3 使用「CREATE INDEX」建立索引
6 索引的名稱
7 刪除索引
drop index
8 數值欄位型態與AUTO_INCREMENT
last_insert_id()
bigint unsigned not null auto_increment unique, serial
9 查詢表格與索引資訊
9.1 表格相關資訊
show
9.2 索引相關資訊
show index

MySQL 超新手入門(10)子查詢

1 一個敘述中的查詢敘述
2 WHERE、HAVING子句與子查詢
2.2 「IN」運算子
2.3 其它運算子
all, any, some
2.4 多欄位子查詢
3 SELECT子句與子查詢
4 FROM子句與子查詢
5 資料維護與子查詢
5.1 新增
insert
5.2 修改
update .. set ..
5.3 刪除
delete
6 關聯子查詢
7 子查詢與結合查詢

MySQL 超新手入門(11)Views

1 View的應用
2 建立需要的View
create or replace view
describe
3 修改View
alter view
4 刪除View
drop view if exists
5 資料維護與View
5.1 使用View元件執行資料維護
5.2 使用「WITH CHECK OPTION」
cascade, local
6 View的演算法
7 View的維護與資訊
7.1 檢驗View的正確性
7.2 取得View的相關資訊

MySQL 超新手入門(12)Prepared Statement

1 使用者變數
set
2 Prepared Statements的應用
3 建立、執行與移除Prepared Statements
prepare .. from ..
execute .. using ..
deallocate/drop prepare
4 Prepared Statements的參數
5 有效範圍

MySQL 超新手入門(13)Stored Routines 入門

1 Stored Routines的應用
create procedure
call
create function
1.1 Stored Procedures介紹
drop procedure
1.2 Stored Functions介紹
create function
return
drop function
2 在MySQL Workbench中管理Stored routines
2.1 SQL Script、DELIMITER與Stored routines
delimiter
begin .. end
returns, return
2.2 管理Stored Procedures
alter stored procedure
drop stored procedure
2.3 管理Stored Functions
create function
alter function
drop function
3 Stored Routines的參數
3.1 Stored Functions的參數
3.2 Stored Procedures的參數
in, out, inout

MySQL 超新手入門(14)Stored Routines 的變數與流程

1 宣告與使用變數
declare, set
2 判斷
2.1 IF
if .. then .., elseif, else, end if
2.2 CASE
case, when .. then .., else, end case
3 迴圈
3.1 WHILE
while, end while
3.2 REPEAT
repeat, until, end repeat
3.3 LOOP
loop, end loop
4 標籤
leave
[label]:
iterate

MySQL 超新手入門(15)Stored Routines 進階

1 錯誤編號
MySQL錯誤編號、SQLSTATE
2 Handlers
declare .. condition for ..
declare .. cursor for ..
declare .. handler for ..
exit, continue
3 Conditions
4 Cursors
open, fetch,
5 設定、修改與刪除Stored routines
5.1 建立Stored routines時的設定
LANGUAGE {SQL}
[NOT] DETERMINISTIC
SQL SECURITY { DEFINER | INVOKER }
COMMENT ‘說明字串’
5.2 修改Stored routines設定
alter procedure/function
5.3 刪除Stored routines
6 查詢Stored routines的相關資訊

MySQL 超新手入門(16)Triggers

1 Triggers的應用
2 建立Triggers
create trigger .. on .. for each row ..
before, after
insert, update, delete
3 刪除Triggers
drop trigger if exits
4 OLD與NEW關鍵字
5 查詢Triggers的相關資訊

MySQL 超新手入門(17)查詢 information_schema

1 information_schema資料庫
2 SHOW指令
2.1 資料庫元件資訊
show database/schemas/table/table status/columns/full columns/index/triggers
2.2 建立元件資訊
show create database/table/function/procedure/view
2.3 字元集與collation
show character set/collation
2.4 其它資訊
show engines
show global/session status/variables
3 DESCRIBE指令
4 mysqlshow
using in command line

MySQL 超新手入門(18)錯誤處理與查詢

1 錯誤的資料
set sql_mode = ' '/'STRICT_TRANS_TABLES'/'STRICT_ALL_TABLES'
2 Non-Strict模式
session, global
2.1 數值
2.2 列舉(ENUM)與集合(SET)
2.3 字串轉換為其它型態
2.4 NULL與NOT NULL
2.5 Strict模式與IGNORE關鍵字
3 其它設定
set sql_mode = 'STRICT_ALL_TABLES,ALLOW_INVALID_DATES'
NO_ZERO_DATES, NO_ZERO_IN_DATES, ERROR_FOR_DIVISION_BY_ZERO
4 查詢錯誤與警告
show warnings/error
perror (using in command line)

MySQL 超新手入門(19)匯入與匯出資料

1 備份與回復
2 使用SQL敘述匯出資料
SELECT .. INTO OUTFILE ..
fields terminated by/[optionally] enclosed by/escaped by
lines starting by/terminated by
3 使用SQL敘述匯入資料
3.1 指定資料檔案
load data [local] infile ..
3.2 設定資料格式
3.3 處理匯入的資料
3.4 索引鍵重複
ignore, replace
3.5 匯入資訊
records, deleted, skipped, warnings
4 使用mysqldump程式匯出資料
mysqldump in command line
5 使用mysqlimport程式匯入資料
mysqlimport in command line

MySQL 超新手入門(20)效率

1 索引
1.1 索引的種類
FULLTEXT, SPATIAL
1.2 建立需要的索引
1.3 建立部份內容的索引
2 判斷條件的設定
4 EXPLAIN與查詢敘述
5 資料維護
6 LIMIT子句
7 使用暫時表格
8 儲存引擎

沒有留言:

張貼留言