Home >Database >Mysql Tutorial >How to Fix the 'ERROR: Loading local data is disabled' MySQL Error?

How to Fix the 'ERROR: Loading local data is disabled' MySQL Error?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-29 20:48:13116browse

How to Fix the

Resolving "ERROR: Loading local data is disabled" Issue: A Step-by-Step Guide

The error message "ERROR: Loading local data is disabled" indicates that local data loading is not enabled on both the client and server sides. To resolve this issue, follow these steps:

Step 1: Enable Local Data Loading on the Server Side

  1. Connect to MySQL using a command line shell.
  2. Set the global variable local_infile to 1 using the following command:
mysql> SET GLOBAL local_infile=1;
  1. Verify the setting by running:
mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile';

You should see Value | ON.

Step 2: Enable Local Data Loading on the Client Side

  1. Quit the current MySQL server session by issuing the following command:
mysql> quit
  1. Reconnect to the server with the --local-infile=1 flag:
mysql --local-infile=1 -u <username> -p
  1. Enter your password when prompted.

Step 3: Load the Data into Your Database

  1. Select the database you want to load the data into using the USE command.
  2. Execute the LOAD DATA LOCAL INFILE statement as follows:
mysql> LOAD DATA LOCAL INFILE 'path/to/your_data.csv' INTO TABLE your_table;

Example:

Imagine you want to load a CSV file named toys.csv into a table called toys:

CREATE TABLE toys (
  ...
);

LOAD DATA LOCAL INFILE '/Users/BruddaDave/Desktop/toys.csv' INTO TABLE toys
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(..., ...);

After completing these steps, you should be able to successfully load your local data into your MySQL database without encountering the "ERROR: Loading local data is disabled" issue.

The above is the detailed content of How to Fix the 'ERROR: Loading local data is disabled' MySQL Error?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn