exec_file

NAME

exec_file(): Executes queries from given file, residing on server

TYPE

Procedure

DESCRIPTION

This procedure will read and execute a given file. The file is expected to contain valid SQL statements.

The procedure acts in similar manner to the SOURCE command; only the SOURCE command is a mysql command line tool command, and works by reading a file from the client.
exec_file() reads the file from the server machine. It does not require the mysql command line tool, and works exclusively in server side.

Invoker of this procedure must have the FILE privilege, as well as any other privilege required for executing the commands in the input file.

File size cannot be arbitrarily large. At current, a 64K is a hard limit on the contents of the file. Due to internal mechanism, the limit turns lower than 64K, depending on number and length of queries.

Statements are assumed to be separated be semicolons (";"). exec_file() does not interpret DELIMITER commands.

As a general recommendation, you should not use this routine to import dumps, nor should you attempt to ready very large files.

SYNOPSIS

exec_file(IN file_name TEXT CHARSET utf8) 
  MODIFIES SQL DATA

Input:

  • file_name: input file name. This file must exist on the server host; must be readable (some Linux distributions contain AppArmor or similar security enhancements which place strict restrictions on reading files from MySQL). The file is assumed to contain valid SQL statements.
    Refer to the MySQL Manual for complete listing of valid statements.

EXAMPLES

Execute command in file:

call exec_file('/tmp/my_statements.sql');

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

eval(), exec(), exec_single()

AUTHOR

Shlomi Noach
 
common_schema documentation