Change Is Inevitable
  • Home
  • MySQL
    • MySQL-Articles
    • AWS RDS
    • Percona Xtradb Cluster
    • MariaDB
    • Galera Cluster
    • ProxySQL
    • MySQL-Scripts
    • MySQL tools
    • MySQL Resources
  • Tools
    • MySQL Advisor
    • MySQL Random Data Generator
    • Postgresql Random Data Generator
    • Clean Prompt
  • General
    • binary-to-decimal
    • Fermat’s Theorem
    • Review
    • Just for fun
    • Personal
  • Contact Me
    • Copyright
    • MySQL Podcast (Youtube)
    • MySQL Podcast (Spotify)
Recent Posts
  • MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • How to setup and use Percona Binlog Server (PBS)
  • MySQL Major Version Upgrade Checklist – how to
  • InnoDB Flushing is simple – explained
  • MySQL Tools for Performance Tuning and Test Data Generation
Recent Comments
  • Kedar on MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • Jean-François Gagné on MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • Reggie on A Unique Foreign Key issue in MySQL 8.4
  • Kedar on How to fix write latency in MySQL 8.4 Upgrade
  • Kedar on How to fix write latency in MySQL 8.4 Upgrade
Home » sys_exec
Change Is Inevitable

Kedar Vaijanapurkar's Blog for MySQL, technology and various subjects

  • Home
  • MySQL
    • MySQL-Articles
    • AWS RDS
    • Percona Xtradb Cluster
    • MariaDB
    • Galera Cluster
    • ProxySQL
    • MySQL-Scripts
    • MySQL tools
    • MySQL Resources
  • Tools
    • MySQL Advisor
    • MySQL Random Data Generator
    • Postgresql Random Data Generator
    • Clean Prompt
  • General
    • binary-to-decimal
    • Fermat’s Theorem
    • Review
    • Just for fun
    • Personal
  • Contact Me
    • Copyright
    • MySQL Podcast (Youtube)
    • MySQL Podcast (Spotify)

Browsing Tag

sys_exec

1 post

MySQL Load Data Infile with Stored Procedure

  • Kedar
  • November 30, 2010
Did you ever need to run LOAD DATA INFILE in a procedure? May be to automate or dynamically perform the large data file load to the MySQL database. In this…
View Post
MySQL Podcast (Youtube)
RSS feed: MySQL Podcast (Spotify) MySQL Podcast (Spotify)
  • MySQL Major Version Upgrade Checklist (Zero Downtime Strategy)
    Upgrading MySQL major versions in production is never just a version bump - it’s a carefully planned process involving compatibility checks, replication strategy, testing, and controlled cut-over.In this episode, we walk through a practical MySQL Major Version Upgrade Checklist based on real-world DBA workflows. We are covering MySQL replication as base setup for upgrade. It […]
Search:
... ...
  • MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • How to setup and use Percona Binlog Server (PBS)
  • MySQL Major Version Upgrade Checklist – how to
  • InnoDB Flushing is simple – explained
  • MySQL Tools for Performance Tuning and Test Data Generation

35 responses to “MySQL Load Data Infile with Stored Procedure”

  1. venkat Avatar
    venkat
    July 5, 2018

    Not able to download Mysql UDF from below your mentioned url and getting below error

    $ wget http://www.mysqludf.org/lib_mysqludf_sys/lib_mysqludf_sys_0.0.3.tar.gz
    –10:28:38– http://www.mysqludf.org/lib_mysqludf_sys/lib_mysqludf_sys_0.0.3.tar.gz
    => `lib_mysqludf_sys_0.0.3.tar.gz’
    Resolving http://www.mysqludf.org... done.
    Connecting to http://www.mysqludf.org[192.30.252.154]:80... connected.
    HTTP request sent, awaiting response… 404 Not Found
    10:28:39 ERROR 404: Not Found.

    Reply
  2. prashant Avatar
    prashant
    December 19, 2016

    can somebody please create batch file command for load.sh given above, thanks in advance.

    Reply
  3. Amos Avatar
    Amos
    June 9, 2015

    Great post.

    Reply
  4. Aniruddha Avatar
    Aniruddha
    March 25, 2015

    Hi Kedar,

    mysql -uusername -ppassword -e “load data local infile \”$1\” into table $2;”
    In load.sh file, replaced only “ to ” and also debugging the all scenarios.

    Done…. your code is work 🙂

    Thank you very much…

    Regards,
    Aniruddha

    Reply
  5. Aniruddha Avatar
    Aniruddha
    March 24, 2015

    Thanks for the information Kedar ……

    “mysql> CALL sp_load_data(‘/tmp/loadtest.txt’ , ‘optimuserp_gdm.t’);
    +————————————————————-+———+
    | exec_str | ret_val |
    +————————————————————-+———+
    | sh /home/tsd/tmp/load.sh /tmp/loadtest.txt optimuserp_gdm.t | 32256 |
    +————————————————————-+———+
    1 row in set (0.05 sec)

    +—————————————–+
    | Result |
    +—————————————–+
    | Please check file permissions and paths |
    +—————————————–+
    1 row in set (0.05 sec)

    Query OK, 0 rows affected (0.05 sec)

    mysql>
    ”

    please help how to solve this ?.Thanks

    Reply
    1. Kedar Avatar
      Kedar
      March 24, 2015

      Hi Anirudhdha,

      I’d encourage you to debug the issue here as such system call fails. Can you confirm you shell script is running fine manually?

      See too run it from prompt:
      sh /home/tsd/tmp/load.sh /tmp/loadtest.txt optimuserp_gdm.t

      Thanks.

      Reply
  6. Jake Avatar
    Jake
    March 18, 2015

    Hi all

    Got it working 🙂

    I created a batch file called import.bat
    The contents are:

    mysql --user=username --password=password --database=db_name < c:/devc_import2.sql

    The sql file is the script I created in Workbench.

    In the SP the only change I made is: set exec_str="c:/import.bat";

    It worked!

    Hope this helps – I spent a full day trying so many permutations and it turned out to be easy.

    Jake

    Reply
    1. Kedar Avatar
      Kedar
      March 18, 2015

      Nice one Jake… After those permutations it must be a What the Fun moment for you 🙂

      Cheers.

      Reply
  7. Jake Avatar
    Jake
    March 18, 2015

    Hi
    Did anyone manage to get this to work on a windows server?
    I’ve tried but unsuccessful.
    I created a SP with the following:
    declare exec_str varchar(500);
    set exec_str="cmd c:/devc_import2.txt";
    do sys_exec(exec_str);

    The dvc_import.txt is as follows:


    mysql --user=username --password=password --database=bd_name -e "load data local infile 'c:/Allproperties.csv' into table devc_import FIELDS TERMINATED BY ','ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 ROWS (dc_PropertyID,@DevelopmentID,@RegionID,@HouseTypeID,......)set dc_DevelopmentID = IF(@DevelopmentID='',null,@DevelopmentID),......;"

    The csv file I’m trying to import has only 410 rows but has approx. 145 columns.

    I can run the contents od the txt file directly form a command window and it works great but when I run the SP the browser just waits. Looking in task manager I see the cmd process but it doing nothing.

    Any help most appreciated.

    Jake

    Reply
  8. Uma Avatar
    Uma
    February 11, 2015

    How about on Windows?

    Reply
    1. Kedar Avatar
      Kedar
      February 16, 2015

      Hi Uma,

      I’ve not tried this on Windows though I expect it should be working… would you mind sharing your attempt or error you faced!?

      Regards,
      Kedar.

      Reply
  9. Red83 Avatar
    Red83
    April 19, 2013

    I am trying to call a batch file from sys_exec as

    do sys_exec(‘E:\load.bat’)

    but it is not giving any result

    Reply
    1. Kedar Avatar
      Kedar
      April 20, 2013

      Hey Red83,

      Did you check the comments? I’m pasting it here again for your convenience:

      Just verify:
      – Make sure your dll / udf is installed & working.
      – What’s your bat file? Does it execute the load command when run manually, from outside the SP?
      – You changed SP, no path issues and all?
      – Check if mysql can access your bat file (are you on Win7/Vista)

      If sys_exec is running fine on your windows than there shouldn’t be any issue for it to run in above procedure.

      I’m sorry I haven’t tried it on windows (as I’m mostly on *nix) but if you can post your changes in above code I may try to lookup !!

      Let me know.

      Reply
  10. Emmanuel Avatar
    Emmanuel
    January 30, 2013

    I try to execute sys_exec with string (not from file).
    but it gives me error ‘Please check file permissions and paths’

    please help how to solve this ?.Thanks

    Reply
    1. Kedar Avatar
      Kedar
      January 31, 2013

      Hey Emmanuel,

      Can you tell me what exactly you’re doing?
      You can also debug this by checking out what exact value is being passed in the exec_str by adding an extra line to the procedure as follows:

      set exec_str=concat(“sh /tmp/load.sh “,in_filepath,” “, in_db_table);
      select exec_str;
      set ret_val=sys_exec(exec_str);

      Let me know,
      Thanks.

      Reply
Change Is Inevitable
Designed & Developed by Code Supply Co.