简体   繁体   English

如何在mysql中使用过程导出表数据

[英]How export table data using procedure in mysql

We need to export some table's data into file. 我们需要将某些表的数据导出到文件中。 We are selecting the table names programmatically. 我们正在以编程方式选择表名称。 So we are trying to do this using a procedure, we have created a sample procedure 因此,我们尝试使用一个过程来执行此操作,我们创建了一个示例过程

DELIMITER $$
CREATE PROCEDURE export_dynamic() 
BEGIN 
set @myvar = 'SELECT * INTO OUTFILE ''E:\\MYSQL-DUMP\\tabletest.txt'' FROM tabletest'; 
PREPARE STMT FROM @myvar;
EXECUTE STMT;
DEALLOCATE PREPARE STMT;
END; 
$$

But when we CALL this procedure we are getting following Error 但是,当我们调用此过程时,我们会遇到以下错误

CALL export_dynamic()   Error Code: 1. Can't create/write to file 'E:MYSQL-DUMP abletest.txt' (Errcode: 22 - Invalid argument)  0.000

When we run the following query In MySQL workbench works fine 当我们运行以下查询时,在MySQL工作台中工作正常

SELECT * INTO OUTFILE 'E:\\MYSQL-DUMP\\tabletest.txt' FROM tabletest

Is there any way to export a table using mysql procedure? 有什么方法可以使用mysql过程导出表?

Look at the err msg. 看看错误信息。 The interface you're using is eating your backslashes. 您正在使用的界面正在吃反斜杠。

Try using forward slashes, mysql often will translate them into the required. 尝试使用正斜杠,mysql通常会将其转换为所需的斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM