mysql必會知識

1 了解SQL

數(shù)據(jù)庫基礎
database table column row primary key

2 mysql 簡介

MySQL是一個關系型數(shù)據(jù)庫管理系統(tǒng),由瑞典MySQL AB 公司開發(fā),目前屬于 Oracle 旗下產(chǎn)品。MySQL 是最流行的關系型數(shù)據(jù)庫管理系統(tǒng)之一,在 WEB 應用方面,MySQL是最好的 RDBMS (Relational Database Management System,關系數(shù)據(jù)庫管理系統(tǒng)) 應用軟件之一。

3 庫和表

  use database;
  show databases;
  show tables;
  show column from table_name;
  show status; #服務器狀態(tài)

4 檢索數(shù)據(jù)

select * from  table_name;
select prod_name,xxx,xxx from table_name;

select DISTINCT pro_id from products;
select prod_name from product LIMIT 5;

5 排序檢索數(shù)據(jù)

select prod_name from products ORDER BY prod_name,prod_name;
select prod_name from products order by prod_name DESC(ASC);

6 過濾數(shù)據(jù)

select prod_name,prod_price from products where  prod_price = xxx;
select prod_name from products where prod_price between 5 and 10;

select prod_name from products where vend_id 1003 and prod_price <= 10;
select prod_name from products where vend_id 1003 or prod_price <= 10;
select prod_name from products where vend_id in (1000,1007) order by prod_name desc;
select prod_name from products where vend_id not_in (1000,1007) order by prod_name desc;

select prod_id from products where prod_name like 'vate%';
select prod_id from products where prod_name like '_vate';

7 正則

select prod_name from products where prod_name REGEXP '.000' order by prod_mame;
select prod_name from products where prod_name REGEXP '.000|0001' order by prod_mame;
[123] = 1|2|3
[0-9a-z]
#字符類
[:alnum:]  # 任意字母和數(shù)組 [a-zA-Z0-9]
[:alpha:]  # 任意字符 [a-zA-Z]
[:blank:]  # 空格和制表[\\t]
[:cntrl:]  # ASCII控制字符(ASCII 0到37和127)
[:digit:]    # 任意數(shù)組 [0-9]
[:graph:]  # 與[:print:]相同,但不包括空格
[:print:] # 任意 可打印字符
[:lower:]  # 任意小寫字母 [a-z]
[:punct:]  # 既不在[:alnum:]又不在[:cntrl:]中的任意字符
[:space:] # 包括 空格在內(nèi)的任意空白字符 [\\f\\n\\r\\t\\v]
[:upper:] #任意大寫字母[A-Z]
[:xdigit:]  # 任意十六進制數(shù)組[a-fA-F0-9]
#重復元字符
*  # 0個或多個匹配
+ # 1個或多個匹配 {1,}
? # 0個或1個匹配{0,1}
{n} # 指定數(shù)目匹配
{n,} # 不少于指定數(shù)目匹配
{n,m} # 匹配數(shù)目的范圍 (m不超過225)
eq: select prod_name from products where prod_name PRGXP '[[:digit:]]{4}'
#定位元字符
^ # 文本開始
$ # 文本介紹
[[:<:]] # 詞的開始
[[:>:]] # 詞的結(jié)束
eq: select prod_name from products where prod_name PRGXP '^[0-9\\.]'
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容