當前位置:首頁 » 存儲配置 » mysql存儲過程into

mysql存儲過程into

發布時間: 2022-10-24 06:14:26

❶ mysql存儲過程中分支語句有哪些

存儲過程:
create procere p()
begin
/*thi procere does nothing*/
end;

1.參數
Parameters 參數
讓我們更進一步的研究怎麼在存儲過程中定義參數1. CREATE PROCEDURE p5
() ...
2. CREATE PROCEDURE p5
([IN] name data-type) ...
3. CREATE PROCEDURE p5
(OUT name data-type) ...
4. CREATE PROCEDURE p5
(INOUT name data-type) ...

2.Conditions and if-then-else 條件式和 if-then-else

3.Loops 循環語句
WHILE ... END WHILE
LOOP ... END LOOP
REPEAT ... END REPEAT
GOTO

4.DECLARE HANDLER syntax 聲明異常處理的語法
DECLARE
{ EXIT | CONTINUE }
HANDLER FOR
{ error-number | { SQLSTATE error-string } | condition }
SQL statement

5.Cursors 游標
游標實現功能摘要:
DECLARE cursor-name CURSOR FOR SELECT ...;
OPEN cursor-name;
FETCH cursor-name INTO variable [, variable];
CLOSE cursor-name;
已現經在可我以們完開成始基著本眼的游事標了務如。聲雖明然游我標們,的打存開儲游過標程,中從的游游標標里語法讀取還,並關沒閉有完游整標。

6.Functions 函數
Summary:
摘要 CREATE FUNCTION
Limitations of functions
函數的限制
我們已經很清楚可以在存儲過程中使用的元素了。下面我要講的是前面沒有提到的函數。

❷ mysql 存儲過程

你應該在做統計吧,估計你不會的就是mysql存儲過程的語法 我之前也寫過 很是郁悶 我給你一段代碼 是我用mysql寫過的一個存儲過程 你看看 主要是了解裡面的語法 看懂了 你所說的需求並不難
有看不懂的地方一起討論 :
begin

declare tikk datetime ;
declare done int default 0;
declare userid int default 0;
declare moleid int default 0;
declare couid int default 0;
declare mname varchar(255) ;
declare opsid int default 0;

declare c1 cursor for Select I_userID,I_operationID from space_operation_record where status<>0 group by I_userID,I_operationID order by createtime desc;
declare continue handler for sqlstate '02000' set done =1;
set tikk = now();
open c1;
repeat
fetch c1 into userid, opsid;
if not done then
select I_moleID from space_operation where status<>0 and ID=opsid into moleid;
if moleid <> '' then
select Nvc_identification from space_operation where status<>0 and ID=opsid into @identiftion;
if moleid > 0 then
Select Nvc_ename from space_mole where status<>0 and ID=moleid into mname;
else
set mname = 'space';
end if;

create temporary table if not exists sp_tab1(id bigint(20),Nvc_content MEDIUMTEXT,I_obyuID bigint(20),I_tID bigint(20),createtime datetime);
INSERT INTO sp_tab1 Select ID,Nvc_content,I_objectID,I_tmID,createtime from space_operation_record where status<>0 and I_operationID=opsid and I_userID=userid ;
select count(*) from sp_tab1 into couid;

set @ihod = 0;
set @listp = '';
set @listpp = '';
set @content0p = '';
set @content0 = '';
while couid > 0 do
select ID,Nvc_content,I_obyuID,createtime,I_tID into @iok,@conuiy,@objiplk,@crtimhr,@tmids from sp_tab1 where ID > @ihod order by ID asc limit 0,1;
if @iok <> '' then
if mname = 'blog' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,tikk);
elseif mname = 'team' then
if(@identiftion = 'addblog' || @identiftion = 'mdyblog') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listpp = CONCAT(@listpp,CONCAT(@objiplk,','));
set @operarry1p = substring_index(@conuiy,'|',1);
set @operarry2p = substring_index(@conuiy,'|',-1);
set @content0p = CONCAT(@content0p,CONCAT(@operarry2p,SPACE(1)));
set @objlistp = substring(@listpp,1,length(@listpp)-1);
end if;
elseif mname = 'space' then
if(@identiftion = 'headphoto' || @identiftion = 'status') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listppr = CONCAT(@listppr,CONCAT(@objiplk,','));
set @operarry1pr = substring_index(@conuiy,'|',1);
set @operarry2pr = substring_index(@conuiy,'|',-1);
set @content0pr = CONCAT(@content0pr,CONCAT(@operarry2pr,SPACE(1)));
set @objlistpr = substring(@listppr,1,length(@listppr)-1);
end if;
else
set @listp = CONCAT(@listp,CONCAT(@objiplk,','));
set @operarry1 = substring_index(@conuiy,'|',1);
set @operarry2 = substring_index(@conuiy,'|',-1);
set @content0 = CONCAT(@content0,CONCAT(@operarry2,SPACE(1)));
set @objlist = substring(@listp,1,length(@listp)-1);
end if;
set @ihod = @iok;
end if;
set couid = couid -1;
end while;

if @content0 <> '' then
set @contentp = CONCAT(@operarry1,concat('|',@content0));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlist);
end if;
end if;
if @content0p <> '' then
if @identiftion = 'addphoto' then
set @contentp = CONCAT(@operarry1p,CONCAT('|',@content0p));
else
set @contentp = CONCAT(@operarry1p,CONCAT(@content0p,'|'));
end if;

Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
if @content0pr <> '' then
set @contentp = CONCAT(@operarry1p,concat('|',@content0pr));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
delete from sp_tab1;
end if;
end if;

until done end repeat;
close c1;
drop temporary table if exists sp_tab1 ;

UPDATE space_operation_play SET status=0;
UPDATE space_operation_display SET status=0;
Select createtime into @ptimes from space_operation_stat where status<>0 order by createtime desc limit 0,1;
if @ptimes <>'' then
create temporary table if not exists sp_tab2(id bigint(20),Nvc_content MEDIUMTEXT,I_userID bigint(20),I_lyuID bigint(20),D_stattime datetime);
INSERT INTO sp_tab2 Select ID,Nvc_content,I_userID,I_tmID,D_stattime from space_operation_stat where status<>0 and createtime=@ptimes order by D_stattime desc limit 0,30;
select count(*) from sp_tab2 into @cou1id;
set @uoj = 0;
while @cou1id > 0 do
select ID,Nvc_content,I_userID,D_stattime,I_lyuID into @io1k,@conui1y,@objipl1k,@crtimh1r,@unlpa from sp_tab2 where ID > @uoj order by ID asc limit 0,1;
if @io1k <> '' then
INSERT INTO space_operation_play(I_statID,Nvc_content,D_stattime,I_userID,Createtime,I_tmID) VALUES (@io1k,@conui1y,@crtimh1r,@objipl1k,now(),@unlpa);
set @uoj = @io1k;
end if;
set @cou1id = @cou1id -1;
end while;
drop temporary table if exists sp_tab2 ;
end if;

end

❸ MYSQL如何把存儲過程所返回的結果集插入到表

從存儲過程返回表類型的值也有二種: 1.存儲過程使用浮標參數,即同時指定CURSOR VARYING OUTPUT項.調用者可以使用while及fetch循環遍歷該浮標. 2.直接將存儲過程返回的結果集插入到表中,即使用insert into 表名 exec 存儲過程.此種方式中注意存儲過程返回的結果集列與insert的列要完全對應,可以在insert中指定列名來保證對應關系. ------------------------------------------------------------------------------測試:------------------------------------------------------------------------------ ----建立測試用的臨時表 create table #tmp (colx int,coly int) insert into #tmp values(1,2) insert into #tmp values(2,3) insert into #tmp values(3,4) select * from #tmpGO----創建返回遊標的存儲過程 create proc sp_c @cur CURSOR VARYING OUTPUTASbeginset @cur = CURSOR for select colx from #tmp open @cur /*該過程返回遊標,該游標為colx列的查詢結果*/endGO----創建返回表的存儲過程 create proc sp_dasselect coly from #tmp /*該過程返回coly列的查詢結果*/go----創建用於調用以上二個存儲過程的存儲過程 create proc sp_easbegindeclare @x int declare @cur cursor ----接收游標,並遍歷游標 EXEC sp_c @cur OUTPUT fetch next from @cur into @x while (@@FETCH_STATUS = 0)beginprint @xfetch next from @cur into @xENDclose @curdeallocate @cur ----將存儲過程返回的列值再重新插入源表中 insert into #tmp(coly) EXEC sp_d select * from #tmpendGOEXEC sp_edrop proc sp_c drop proc sp_d

❹ mysql存儲過程該怎麼做

看懂了 你所說的需求並不難
begin

declare tikk datetime ;
declare done int default 0;
declare userid int default 0;
declare moleid int default 0;
declare couid int default 0;
declare mname varchar(255) ;
declare opsid int default 0;

declare c1 cursor for Select I_userID,I_operationID from space_operation_record where status<>0 group by I_userID,I_operationID
createtime desc;
declare continue handler for sqlstate '02000' set done =1;
set tikk = now();
open c1;
repeat
fetch c1 into userid, opsid;
if not done then
select I_moleID from space_operation where status<>0 and ID=opsid into moleid;
if moleid <> '' then
select Nvc_identification from space_operation where status<>0 and ID=opsid into @identiftion;
if moleid > 0 then
Select Nvc_ename from space_mole where status<>0 and ID=moleid into mname;
else
set mname = 'space';
end if;

create temporary table if not exists sp_tab1(id bigint(20),Nvc_content MEDIUMTEXT,I_obyuID bigint(20),I_tID bigint(20),createtime datetime);
INSERT INTO sp_tab1 Select ID,Nvc_content,I_objectID,I_tmID,createtime from space_operation_record where status<>0 and I_operationID=opsid and I_userID=userid ;
select count(*) from sp_tab1 into couid;

set @ihod = 0;
set @listp = '';
set @listpp = '';
set @content0p = '';
set @content0 = '';
while couid > 0 do
select ID,Nvc_content,I_obyuID,createtime,I_tID into @iok,@conuiy,@objiplk,@crtimhr,@tmids from sp_tab1 where ID > @ihod
ID asc limit 0,1;
if @iok <> '' then
if mname = 'blog' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,tikk);
elseif mname = 'team' then
if(@identiftion = 'addblog' || @identiftion = 'mdyblog') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listpp = CONCAT(@listpp,CONCAT(@objiplk,','));
set @operarry1p = substring_index(@conuiy,'|',1);
set @operarry2p = substring_index(@conuiy,'|',-1);
set @content0p = CONCAT(@content0p,CONCAT(@operarry2p,SPACE(1)));
set @objlistp = substring(@listpp,1,length(@listpp)-1);
end if;
elseif mname = 'space' then
if(@identiftion = 'headphoto' || @identiftion = 'status') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listppr = CONCAT(@listppr,CONCAT(@objiplk,','));
set @operarry1pr = substring_index(@conuiy,'|',1);
set @operarry2pr = substring_index(@conuiy,'|',-1);
set @content0pr = CONCAT(@content0pr,CONCAT(@operarry2pr,SPACE(1)));
set @objlistpr = substring(@listppr,1,length(@listppr)-1);
end if;
else
set @listp = CONCAT(@listp,CONCAT(@objiplk,','));
set @operarry1 = substring_index(@conuiy,'|',1);
set @operarry2 = substring_index(@conuiy,'|',-1);
set @content0 = CONCAT(@content0,CONCAT(@operarry2,SPACE(1)));
set @objlist = substring(@listp,1,length(@listp)-1);
end if;
set @ihod = @iok;
end if;
set couid = couid -1;
end while;

if @content0 <> '' then
set @contentp = CONCAT(@operarry1,concat('|',@content0));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid
createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlist);
end if;
end if;
if @content0p <> '' then
if @identiftion = 'addphoto' then
set @contentp = CONCAT(@operarry1p,CONCAT('|',@content0p));
else
set @contentp = CONCAT(@operarry1p,CONCAT(@content0p,'|'));
end if;

Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
if @content0pr <> '' then
set @contentp = CONCAT(@operarry1p,concat('|',@content0pr));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
delete from sp_tab1;
end if;
end if;

until done end repeat;
close c1;
drop temporary table if exists sp_tab1 ;

UPDATE space_operation_play SET status=0;
UPDATE space_operation_display SET status=0;
Select createtime into @ptimes from space_operation_stat where status<>0 order by createtime desc limit 0,1;
if @ptimes <>'' then
create temporary table if not exists sp_tab2(id bigint(20),Nvc_content MEDIUMTEXT,I_userID bigint(20),I_lyuID bigint(20),D_stattime datetime);
INSERT INTO sp_tab2 Select ID,Nvc_content,I_userID,I_tmID,D_stattime from space_operation_stat where status<>0 and createtime=@ptimes order by D_stattime desc limit 0,30;
select count(*) from sp_tab2 into @cou1id;
set @uoj = 0;
while @cou1id > 0 do
select ID,Nvc_content,I_userID,D_stattime,I_lyuID into @io1k,@conui1y,@objipl1k,@crtimh1r,@unlpa from sp_tab2 where ID > @uoj order by ID asc limit 0,1;
if @io1k <> '' then
INSERT INTO space_operation_play(I_statID,Nvc_content,D_stattime,I_userID,Createtime,I_tmID) VALUES (@io1k,@conui1y,@crtimh1r,@objipl1k,now(),@unlpa);
set @uoj = @io1k;
end if;
set @cou1id = @cou1id -1;
end while;
drop temporary table if exists sp_tab2 ;
end if;

end

❺ 關於mysql中存儲過程select into無法賦值詭異的事情,請大神求教,這是怎麼回事

方法是沒有問題,可以在insert into 前面加一條select userName ; 用於檢查是否正常獲取到值。

❻ 五、MYSQL存儲過程和函數

• create procere用來創建 存儲過程 ,create function用來創建 函數

Delimiter命令是改變語句的結束符 ,MySQL默認的結束符為;號,由於procere和function中的;號並不代表創建的結束,所以要替換成另外的結束符以便表示創建的結束
• rontine_body子句可以包含一個簡單的SQL語句,也可以包含多個SQL語句, 通過begin…end將這多個SQL語句 包含在一起
• MySQL存儲過程和函數中也可以包含類似create和drop等DDL語句
• comment子句用來寫入對存儲過程和函數的注釋
Language子句用來表示此存儲過程和函數的創建語言
存儲過程和函數被標注為deterministic表明當輸入相同的參數是會返回相同的結果,反之如果是not deterministic則表示相同參數不會是相同結果,默認是not deterministic

相關屬性短語只有咨詢含義,並不是強制性的約束

• Drop procere/function語句用來 刪除指定名稱的存儲過程或函數

• Begin…end語句通常出現在存儲過程、函數和觸發器中,其中 可以包含一個或多個語句 ,每個語句用;號隔開

• 標簽label可以加在begin…end語句以及loop, repeat和while語句
語句中通過iterate和leave來控制流程,iterate表示返回指定標簽位置,leave表示跳出標簽

Declare語句通常用來聲明本地變數、游標、條件或者handler
Declare語句只允許出現在begin … end語句中而且必須出現在第一行
Declare的順序也有要求,通常是先聲明本地變數,再是游標,然後是條件和handler

• 本地變數可以通過declare語句進行聲明
聲明後的變數可以通過select … into var_list進行賦值,或者通過set語句賦值,或者通過定義游標並使用fetch … into var_list賦值
• 通過declare聲明變數方法:

• MySQL支持if,case,iterate,leave,loop,while,repeat語句作為存儲過程和函數中的 流程式控制制語句 ,另外return語句也是函數中的特定流程式控制制語句

• Case語句在存儲過程或函數中表明了 復雜的條件選擇語句

• IF語句在存儲過程或函數中表明了 基礎的條件選擇語句

其中在 function 裡面,只有 DETERMINISTIC, NO SQL 和 READS SQL DATA 被支持。如果我們開啟了 bin-log, 我們就必須為我們的 function 指定一個參數。
在 MySQL 中創建函數時出現這種錯誤的解決方法:
set global log_bin_trust_function_creators=TRUE;

• Iterate語句 僅出現在loop,repeat,while循環語句中,其含義表示重新開始此循環

• Leave語句表明 退出指定標簽的流程式控制制語句塊
• 通常會用在begin…end,以及loop,repeat,while的循環語句中

• Loop語句是存儲過程或函數中表達 循環執行 的一種方式

• repeat語句是存儲過程或函數中表達 循環執行 的一種方式

• while語句是存儲過程或函數中表達 循環執行 的一種方式

• Return語句用在 函數中,用來終結函數的執行並將指定值返回給調用者

• Cursor游標用來 聲明一個數據集
• 游標的聲明必須在變數和條件聲明之後,在handler聲明之前

• Cursor close語句用來 關閉之前打開的游標

• Cursor declare語句用來聲明一個游標和指定游標對應的數據集合, 通常數據集合是一個select語句

• Cursor fetch語句用來獲取游標指定數據集的 下一行數據 並將各個欄位值賦予後面的變數

• Open cursor語句用來打開一個之前已經 聲明好的游標

• Declare condition語句命名 特定的錯誤條件 ,而該特定錯誤可以在declare…handler中指定 處理方法

• 比如在MySQL中1051error code表示的是unknown table的錯誤,如果要對這
個錯誤做特殊處理,可以用三種方法:

• Declare handler語句用來聲明一個handler來處理一個或多個特殊條件,當其中的某個條件滿足時則觸發其中的statement語句執行
• Statement可以是一個簡單SQL語句,也可以是begin…end組成的多個語句

• Handler_action子句聲明當執行完statement語句之後應該怎麼辦

Condition_value的值有以下幾種:

• 當condition發生但沒有聲明handler時,則存儲過程和函數依照如下規則處理

• create trigger語句用來創建一個觸發器,觸發器的作用是當表上有對應SQL語句發生時,則觸發執行
• 觸發器創建時需要 指定對應的表名 tbl_name

Definer關鍵詞用來指定trigger的安全環境
• Trigger_time指定觸發器的執行時間,BEFORE和AFTER指定觸發器在表中的 每行數據修改前或者後 執行
• Trigger_event指定觸發該觸發器的具體 事件
• INSERT當新的一行數據插入表中時觸發,比如通過執行insert,load data,replace語句插入新數據
• UPDATE當表的一行數據被修改時觸發,比如執行update語句時
• DELETE當表的一行數據被刪除時觸發,比如執行delete,replace語句時
• 當執行insert into … on plicate key update語句時,當碰到重復行執行update時,則觸發update下的觸發器
• 從5.7.2版本開始,可以創建具有相同trigger_time和trigger_event的同一個表上的多個觸發器,默認情況下按照創建的時間依次執行,通過 指定FOLLOWS/PRECEDES改變執行順序 ,即FOLLOWS時表示新創建的觸發器後執行,PRECEDES則表示新觸發器先執行
• Trigger_body表示觸發器觸發之後要執行的一個或多個語句,在內部可以引用涉及表的欄位, OLD.col_name表示行數據被修改或刪除之前的欄位數據,NEW.col_name表示行數據被插入或修改之後的欄位數據

• Drop trigger語句用來 刪除一個觸發器

• If exists短語用來避免刪除不存在的觸發器時引發報錯
當你執行drop table時,表上的觸發器也被drop掉了

❼ Mysql存儲過程

set temp1=SELECT str_split(log,'"',1);

改成
set temp1=str_split(log,'"',1);

❽ mysql存儲過程易語言調用

delete from 是刪除的意思。

insert into 是添加記錄。
網路一下mysql語句,好好學習一下再用吧。

❾ mysql存儲過程

MySQL存儲過程創建的格式如下:
CREATE PROCEDURE 過程名 ([過程參數[,...]])[特性 ...] 過程體
舉例代碼如下:

CREATE PROCEDURE proc1(OUT s int) BEGIN SELECT COUNT(*) INTO s FROM user; END

存儲過程根據需要可能會有輸入、輸出、輸入輸出參數,這里有一個輸出參數s,類型是int型,如果有多個參數用","分割開。
過程體的開始與結束使用BEGIN與END進行標識。
注意:MySQL在5.0以前並不支持存儲過程

❿ mysql 存儲過程中的select into outfile語句生成的文件放哪裡

表數據導出到一個文本文件最簡單的方法是使用SELECT... INTO OUTFILE語句的查詢結果直接導出到一個文件在伺服器主機上。
導出數據的SELECT...INTO OUTFILE聲明:

這句話的語法結合了常規的SELECT INTO OUTFILE文件名的末尾。默認的輸出格式是相同的LOAD DATA,所以下面的語句導出tutorials_tbl的表製表符分隔的,換行結尾的文件到/tmp/tutorials.txt:

mysql> SELECT * FROM tutorials_tbl
-> INTO OUTFILE '/tmp/tutorials.txt';

也可以更改輸出格式,使用選項來指示如何引用和分隔列和記錄。 CRLF終止線要導出tutorial_tbl的CSV格式的表格,使用這樣的語句:

mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/tutorials.txt'
-> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
-> LINES TERMINATED BY ' ';

SELECT ... INTO OUTFILE具有以下屬性:

  • 由MySQL伺服器直接創建輸出文件,這樣的文件名應指定您希望在伺服器主機上的文件將被寫入。沒有本地版本的LOAD DATA LOCAL版本的類似的語句。

  • 必須要有MySQL的FILE許可權才能執行的SELECT... INTO語句。

  • 輸出文件必須不存在。這可以防止MySQL從會破壞文件可能重要。

  • 應該在伺服器主機上或一些方法來檢索文件從該主機的登錄帳戶。否則SELECT... INTO OUTFILE可能是沒有價值的。

  • 在Unix下,創造了世界可讀的文件和所擁有的MySQL伺服器。這意味著雖然就可以讀取該文件,但是不能夠刪除它。

  • 作為原始數據的導出表:

    使用mysqlmp程序復制或備份表和資料庫。它可以寫表輸出的原始數據文件或為一組的INSERT語句重新創建該表中的記錄。
    轉儲一個表,必須指定一個數據文件 - 選項卡上的選項,表示想要的MySQL伺服器寫入文件所在的目錄。


    使用mysqlmp程序復制或備份表和資料庫。它可以寫表輸出的原始數據文件,或為一組的INSERT語句重新創建該表中的記錄。
    轉儲一個表,必須指定一個數據文件 - 選項卡上的選項,表示想要的MySQL伺服器寫入文件所在的目錄。

  • $ mysqlmp -u root -p --no-create-info

  • --tab=/tmp TUTORIALS tutorials_tbl

  • password ******

  • 在SQL格式導出表的內容或定義:

    一個表中的SQL格式導出到一個文件,使用這樣的命令:

  • $ mysqlmp -u root -p TUTORIALS tutorials_tbl > mp.txt

  • password ******

  • 這將創建文件的內容如下:

  • -- MySQL mp 8.23

  • --

  • -- Host: localhost Database: TUTORIALS

  • ---------------------------------------------------------

  • -- Server version 3.23.58


  • --

  • -- Table structure for table `tutorials_tbl`

  • --


  • CREATE TABLE tutorials_tbl (

  • tutorial_id int(11) NOT NULL auto_increment,

  • tutorial_title varchar(100) NOT NULL default '',

  • tutorial_author varchar(40) NOT NULL default '',

  • submission_date date default NULL,

  • PRIMARY KEY (tutorial_id),

  • UNIQUE KEY AUTHOR_INDEX (tutorial_author)

  • ) TYPE=InnoDB;


  • --

  • -- Dumping data for table `tutorials_tbl`

  • --


  • INSERT INTO tutorials_tbl

  • VALUES (1,'Learn PHP','John Poul','2007-05-24');

  • INSERT INTO tutorials_tbl

  • VALUES (2,'Learn MySQL','Abl S','2007-05-24');

  • INSERT INTO tutorials_tbl

  • VALUES (3,'JAVA Tutorial','Sanjay','2007-05-06');

  • 要轉儲多個表,他們的名字所有的資料庫名稱參數。要轉儲整個資料庫,不指定任何錶後的資料庫,如下所示:

  • $ mysqlmp -u root -p TUTORIALS > database_mp.txt

  • password ******

  • 所有可用的資料庫備份主機上使用以下命令:

  • $ mysqlmp -u root -p --all-databases > database_mp.txt

  • password ******

  • 在SQL格式導出表的內容或定義:

    這些方法可用於實現資料庫的備份策略。
    表或資料庫復制到另一台主機:

    如果要復制的表或資料庫從一個MySQL伺服器,然後使用mysqlmp資料庫名和表名。

    在源主機上運行以下命令。這將轉儲完整的資料庫到mp.txt文件:

  • $ mysqlmp -u root -p database_name table_name > mp.txt

  • password *****

  • 復制完整的資料庫,而不使用一個特定的表名稱,如上面所解釋。

    現在,FTP mp.txt文件在另一台主機上,使用下面的命令。在運行此命令之前,請確保已創建目標伺服器上的資料庫名稱。

  • $ mysql -u root -p database_name < mp.txt

  • password *****

  • 另一種方法,而無需使用一個中間文件來完成,mysqlmp輸出直接通過網路發送到遠程的MySQL伺服器。如果可以連接到兩台伺服器的cookbook 資料庫所在的主機上,使用以下命令:

  • $ mysqlmp -u root -p database_name

  • states | mysql -h other-host.com database_name

  • 命令mysqlmp的一半連接到本地伺服器,並寫入轉儲輸出管道。 MySQL的一半的命令連接到遠程MySQL伺服器otherhost.com。它讀取輸入管和其他host.com伺服器發送的每個語句。

熱點內容
數據加密技術的實現 發布:2025-05-16 20:12:49 瀏覽:157
華為p9擴存儲 發布:2025-05-16 20:03:22 瀏覽:413
如何用蘋果ipad登錄安卓微信 發布:2025-05-16 19:58:51 瀏覽:138
預編譯error技巧 發布:2025-05-16 19:57:42 瀏覽:779
php地址正則表達式 發布:2025-05-16 19:44:01 瀏覽:467
oracle存儲過程優點 發布:2025-05-16 19:41:36 瀏覽:613
無法訪問g盤拒絕訪問 發布:2025-05-16 19:32:57 瀏覽:118
阿里雲伺服器如何把c盤變成d盤 發布:2025-05-16 19:12:36 瀏覽:496
unix環境高級編程學習 發布:2025-05-16 19:11:49 瀏覽:422
如何將20的硝酸配置成5的 發布:2025-05-16 19:04:42 瀏覽:971