MySQL簡明入門教程

2021-07-22 13:10:15 字數 3465 閱讀 2073

宣告:sql關鍵字不區分大小寫,注釋使用--

-- 建立mt_test這個資料庫

create datebase mt_test;

-- 選擇使用資料庫,意思是後面的操作的資料庫表預設使用該資料庫

use mt_test;

-- 刪除資料庫

drop datebase mt_test;

-- 建立表,f_id是自增欄位,f_id也是主鍵,要求插入的每條資料的f_id不能重

create

table t_log (

f_id bigint(20) not

null auto_increment,

f_opt_type bigint(20) not

null,

f_opt_content varchar(256) default

'0',

f_sku_id bigint(20) default

'0',

f_item_id bigint(20) default

'0',

f_distributor_id bigint(20) default

'0',

f_supplier_id bigint(20) default

'0',

f_seller_id bigint(20) default

'0',

f_spec varchar(256) default

null,

f_sale_price bigint(20) default

'0',

f_wd_price bigint(20) default

'0',

f_ratio bigint(20) default

'0',

f_create_time datetime default

null,

f_supplier_sku_id bigint(20) default

'0',

f_dis_sku_id bigint(20) default

'0',

f_platform_ratio bigint(20) default

'0',

f_dis_shop_id bigint(20) default

'0',

f_dis_status bigint(20) not

null

default

'0',

f_supplier_status bigint(20) not

null

default

'0',

f_sup_dis_status bigint(20) not

null

default

'0',

f_dis_seller_status bigint(20) not

null

default

'0',

primary

key (f_id)

) engine=innodb auto_increment=1

default charset=utf8;

-- 檢視表字段詳情

desc t_log;

-- 檢視建表語句

show

create

table t_log;

-- 檢視資料庫包含的資料庫表列表

show tables;

-- 刪除表,包括表裡面的資料全部刪了

drop

table t_log;

-- 表插入資料

-- 通過key=value的形式可以按照任意順序給字段賦值,也可以省去不必要的字段賦值,而且看起來很清晰,建議**中都使用這種方式

insert

into t_log set f_opt_type=1,f_opt_content='opt_context內容部分',f_sku_id=1,f_item_id=2,f_create_time=now();

-- 表刪除資料

delete

from t_log where f_id=11;

-- 表更新資料,一般要求加where語句,表明要更新的記錄條件,否則會更新整個表,很可怕的

update t_log set f_sku_id=11

where f_id=1;

-- 表查詢資料,要查詢的字段一一列出,不要使用*

select f_id,f_create_time from t_log;

-- 選取所有欄位的資料,不要使用*,這裡使用where加了選擇條件

select f_id,f_opt_type,f_opt_content,f_sku_id,f_item_id,f_distributor_id,f_supplier_id,f_seller_id,f_spec,f_sale_price,f_wd_price,f_ratio,f_create_time,f_supplier_sku_id,f_dis_sku_id,f_platform_ratio,f_dis_shop_id,f_dis_status,f_supplier_status,f_sup_dis_status,f_dis_seller_status from t_log where f_id>10;

-- and使用,表示要同時具備

select f_id,f_create_time from t_log where f_id=3

and f_create_time<'2015-06-04 00:00:00';

-- or使用,只要滿足其一就可以

select f_id,f_create_time from t_log where (f_id=3

or f_id=4) and f_create_time<'2015-06-04 00:00:00';

-- 計數count(1)統計記錄數

select

count(1) from t_log where f_id<100;

-- 對結果排序,asc公升序,desc降序

select f_id,f_create_time from t_log ordey by f_id asc;

-- 連表查詢,查詢使用者的uid,uin,mobile,由於uid在uid表,所以需要連表,兩個表中乙個使用者的uin相同,

-- 所以可以用這個欄位來連表,此外由於表名太長,這裡用了表名別稱

select a.f_uin,a.f_mobile,b.f_uid from t_user_41 a,t_uid_user_map_40 b where a.f_uin=b.f_uin;

MySql入門教程

一 連線mysql 格式 mysql h主機位址 u使用者名稱 p使用者密碼 1 例1 連線到本機上的mysql。首先在開啟dos視窗,然後進入目錄 mysqlbin,再鍵入命令mysql uroot p,回車後提示你輸密碼,如果剛安裝好mysql,超級使用者root是沒有密碼的,故直接回車即可進入...

mysql入門教程簡書 mysql入門基礎

1.mysql各個版本的重要性介紹 mysql community server 社群版本,開源免費,但不提供官方技術支援。mysql enterprise edition 企業版本,需付費,購買了之後可以 支援 mysql cluster 集群版,開源免費。可將幾個mysql server封裝成乙...

MySQL零基礎入門教程!

手把手教你入門mysql零基礎入門教程!目前mysql已經成為最為流行的開源關係資料庫系統,並且一步一步地占領了原有商業資料庫的市場。可以看到 google facebook yahoo 網易 久遊等大公司都在使用 mysql 資料庫,甚至將其作為核心應用的資料庫系統。而 mysql 資料庫也不再僅...