Using LOAD DATA INFILE command in a stored procedure

二次信任 提交于 2019-12-10 15:12:44

问题


Is this possible at all? I read on a few websites that one can not use LOAD DATA command inside a procedure.


回答1:


No, it is not possible due to security reasons, I suppose. However, you can generate "LOAD DATA" queries for tables in a database using this trick (return a series of queries for each table: truncate table before load data, then disable keys, then load data, then enable keys):

SELECT CONCAT('TRUNCATE TABLE ',table_name,'; ALTER TABLE ',table_name,' DISABLE KEYS;    LOAD DATA INFILE "',table_name,'.txt" INTO TABLE ',table_name,' FIELDS TERMINATED BY "\\t" LINES TERMINATED BY "\\n"; ALTER TABLE ',table_name,' ENABLE KEYS; ')
FROM information_schema.`TABLES` as infs
WHERE infs.`TABLE_SCHEMA`=DATABASE()
AND infs.`TABLE_TYPE`!='VIEW';

After you run this query, rows resulted are queries for transferring data. I use it when moving a full database content to another. Of course, in that query you can filter your needed tables using more conditions. Hope it helps.



来源:https://stackoverflow.com/questions/17967883/using-load-data-infile-command-in-a-stored-procedure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!