Mysql 用臨時表實現二次檢索

2021-05-24 14:29:16 字數 733 閱讀 7560

mysql的臨時表是針對每次連線有效,連線斷開則臨時表也關閉。在mysql掛接到伺服器,有多個使用者訪問時,mysql會針對每個使用者新建乙個連線,所以每個使用者訪問的臨時表是不同的。基於這樣的原理,用臨時表來儲存第一次搜尋的結果是再好不過了。

首先,我們建立乙個物理表:

create table user (userid int not null,

username varchar(500));

該物理表作為搜尋的實體,插入幾條資料

insert into user values(1,'asdgjalsgfio');

insert into user values(2,'sagewwfasf');

insert into user values(3,'pkpobjuyhgf');

insert into user values(4,'tttttttywfasf');

第二步:執行第一次檢索:

drop table if exists temp_user;  //如果臨時表存在,刪除

create temporary temp_user select * from user where username like '%asf%';  //建立臨時表temp_user,並將搜尋結果插入臨時表中

第三步:執行第二次檢索:

select * from temp_user where username like '%ttt%';                 

mysql 臨時表 漢字 mysql的臨時表用法

delimiter use qgroupdata drop procedure if exists ex print bg kdd search create definer root procedure ex print bg kdd search where varchar 2000 查詢條件 ...

MySQL用臨時表造資料

採用臨時表 建立臨時資料表tmp table create table tmp table id int,primary key id 用 python或者bash 生成 100w 記錄的資料檔案 python瞬間就會生成完 python 推薦 python c for i in range 1,1...

mysql注入 二次注入

場景 系統對傳入值使用mysql escape string做了轉義處理,不能直接注入,但取出值時會自動轉義,而 中未再次轉義就放到sql語句中使用 非預處理方式 使得間接注入成功,實際場景 乙個含有註冊 登入 修改密碼功能的系統。資料庫中有乙個使用者名為admin,密碼為admin的使用者,現註冊...