MySQL's 'SELECT * INTO OUTFILE' command, once used for straightforward data extraction, has become restricted for security reasons. However, the 'LOAD DATA LOCAL INFILE' command remains functional, leaving users wondering why the corresponding 'SELECT INTO OUTFILE LOCAL' option is unavailable.
Why Does 'LOAD DATA LOCAL INFILE' Work?
'LOAD DATA LOCAL INFILE' allows data to be imported from a local file on the server hosting MySQL. Its functionality is solely confined to the server, eliminating security concerns, which is why it remains available.
Why Not 'SELECT INTO OUTFILE LOCAL'?
'SELECT INTO OUTFILE' intends to export data into a text file on the server itself. However, if this file is meant for a remote destination, security measures prevent this action. Unlike 'LOAD DATA INFILE,' which operates within the server, 'SELECT INTO OUTFILE' could potentially allow data to be extracted from the server and transferred to an external location, creating a security vulnerability.
Alternative Approaches
To mitigate this security risk, you can use the 'mysql' command-line tool, as shown in the example provided in the original question. By redirecting the output of a 'SELECT' query to a file using '>', you can effectively transfer data to a local or remote destination, without compromising server security.
MariaDB Functionality
MariaDB, a fork of MySQL, also restricts the 'SELECT INTO OUTFILE' command due to similar security concerns. However, it supports the 'LOAD DATA LOCAL INFILE' command, allowing data import from local server files.
The above is the detailed content of Why is \'SELECT * INTO OUTFILE LOCAL\' Disabled in MySQL but \'LOAD DATA LOCAL INFILE\' Remains Available?. For more information, please follow other related articles on the PHP Chinese website!