当前位置:首页 » 存储配置 » 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 13:00:35 浏览:900
安卓手机如何拼照片 发布:2025-05-16 12:58:23 浏览:373
深入浅出python 发布:2025-05-16 12:56:52 浏览:655
国二c语言vc2010怎么编译运行 发布:2025-05-16 12:53:49 浏览:424
华为热点哪里看密码 发布:2025-05-16 12:53:44 浏览:515
新手如何用java写安卓app 发布:2025-05-16 12:53:07 浏览:402
虚荣挂脚本 发布:2025-05-16 12:50:44 浏览:480
Oracle触发器与存储过程高级编程 发布:2025-05-16 12:49:39 浏览:360
伊兰特悦动有什么配置 发布:2025-05-16 12:48:57 浏览:93
超话等待上传 发布:2025-05-16 12:48:56 浏览:259