Mysql學習筆記

1. 什麼是數據庫?

Excel就是一個數據表,人操作
MySQL是一個數據庫,便於程序操作,便於存儲百萬以上級別的數據

對於數據庫的基本操作:增刪改查
如何對數據庫操作 SQL語句 SQL命令 Structured Query Language(SQL)
1) 每個命令後;
2) 不區分大小寫

2. 數據庫排行

Oracle
MySQL
SQL Server
MongoDB
PostgreSQL
DB2

3. 關係數據庫

是建立在關係模型基礎上的數據庫,藉助於集合代數等數學概念和方法來處理數據庫中的數據。
現實世界中的各種實體以及實體之間的各種聯繫均用關係模型來表示。

Oracle、SQL Server、MySQL

4. 服務器端運行原理圖

(理解什麼是ip和端口號)
Web Application Server
Game Server

5. 如何在MySQL中存儲數據

MySQL下可以創建多個庫(數據庫)database
每個庫下可以創建多個表(表格)table
通過表格存儲我們的數據

6. 什麼是表(Table)(表,行,列,格子)

表有表頭(表頭表示這個表有哪些列)
表裏面的每一行都是我們存儲的數據

7. 假如我們要學生信息和班級信息,如何設計表呢

8. MySQL安裝

默認超級管理員
root root

9. MySQL Workbench介紹

MySQL Command Line Editor

數據庫的鏈接
localhost 127.0.0.1 都代表本機

10. 什麼是表(Table)(表,行,列,格子)

表有表頭(表頭表示這個表有哪些列)
表裏面的每一行都是我們存儲的數據
主鍵(Primary Ke y)
1) 每行數據獨一無二的標識
2) 一個表必須有主鍵(只能有一個主鍵)
3) 不能爲NULL(空值)
4) 由一列或者多列組成
Unique Key
1) 表示該項數據不能重複
2) 允許一條可以爲NULL
外鍵(Foreign Key)
1) 這列數據引用了另外一個表的主鍵

表的關係
一對一 OneToOne
一對多 OneToMany
多對多 ManyToMany

數據庫的創建
表的創建
列的設置

數據添加

數據刪除

數據修改

數據查詢

10. 數據類型

字符串 - char varchar(length) - string
整數 - int - int
小數 - float - float
日期時間 - date - DateTime

默認值
可以爲NULL
自動增長

11. MySQL控制檯

help;
quit;
show databases;
use databasexxx;
show tables;
select * from tablename;

12. MySQL Workbench全面功能學習

http://dev.mysql.com/doc/workbench/en/
添加表
添加數據
數據的查詢
數據的更改
數據的提交
添加數據
修改表結構查看錶結構 alter table

13.

select column_list
from table_name
where filter_condition
order by column_list (desc)
limit rom_limit;

SQL添加註釋
–單行註釋
/* */多行註釋

15. 查詢靜態值

select 'some string';
select 1+1;
select now();
select curdate();
select curtime();
select pi();
select mod(45,7);
select sqrt(25);
可以在查詢的時候通過as 修改這一列的列名

16.

select * from where 1=2;

17. 查詢的時候可以對查詢的列做一些運算

*
/ (除 結果爲浮點)
div (除 結果爲整數)
%  mod (求餘,結果爲浮點數)
 + 
 -

18. 查詢的時候可以使用的功能函數

round() 四捨五入
round(columnname,x)四捨五入保留x位小數
floor()直接舍
ceiling()直接入

19. 字符串操作

concat 
left 
length 
reverse
replace
date_format %m %b %d %y %Y %T %f 
	http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format
get_format(datetime,'EUR' 'ISO' 'USA')
dayofweek
quarter
week
monthname

20.

distinct

21.

where條件
1) 數字 > < = >= <= <>
2) 字符串 = ‘’ > < = >= <= <> !=

邏輯操作
is 僅用is null或is not null
and or not
and 優先級> or

範圍判斷
in (not in)
between (not between) 示例:select * from category where category_id between 1 and 9;
like (not like) % _
示例1:select * from category where name like ‘A%’;
關於NULL的條件
is NULL
is not NULL

22. limit x

limit x1,x2;

23. 創建表

create table tablename(
col_name type not null auto_increment,
col_name type default,
primary key(col_name)
);
查看錶結構
desc tablename;
插入表
insert into tablename(col_name,col_name,col_name)
values(value1,value2,value3,value4,value5);
更新數據
update tablename
set col_name = value,
col_name = value
where condition;
刪除數據
delete from tablename where condition;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章