Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access

Tags:

mysql

load

comment I'm trying ,

mysql> 

LOAD DATA LOCAL INFILE '/var/tmp/countries.csv' 
INTO TABLE countries 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' LINES 
TERMINATED BY '\n' 
IGNORE 1 LINES 
(CountryId,CountryCode,CountryDescription,CountryRegion,LastUpdatedDate,created_by,created_on)
SET created_by = 'DH_INITIAL_LOAD', created_on = current_timestamp();

ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.`

It was working fine, I downloaded pymysql and mysql connector for the python script. I uninstalled and checked still it is not working. The verion and infile is ON,

 select version() -| 8.0.17



mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | ON    |
+---------------+-------+
1 row in set (0.00 sec)
like image 472
Nivethitha Thiyagarajan Avatar asked Aug 11 '20 15:08

Nivethitha Thiyagarajan


People also ask

How do I enable local mysql loading data?

For the mysql client, local data loading capability is determined by the default compiled into the MySQL client library. To disable or enable it explicitly, use the --local-infile=0 or --local-infile[=1] option. For the mysqlimport client, local data loading is not used by default.

What is load data infile?

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server. ( LOCAL is available in MySQL 3.22.

How does load data local infile work?

In contrast, when you execute the LOAD DATA LOCAL INFILE statement, the client attempts to read the input file from its file system, and it sends the contents of the input file to the MariaDB Server. This allows you to load files from the client's local file system into the database.


Video Answer


3 Answers

Using MySql Workbench 8 or above introduced this issue. This fixed it for me:

This restriction can be removed from MySQL Workbench 8.0 in the following way. Edit the connection, on the Connection tab, go to the 'Advanced' sub-tab, and in the 'Others:' box add the line 'OPT_LOCAL_INFILE=1'.

This should allow a client using the Workbench to run LOAD DATA INFILE as usual.

Quoted from this link: https://bugs.mysql.com/bug.php?id=91872

like image 174
big_water Avatar answered Oct 16 '22 17:10

big_water


Known issue: https://bugs.mysql.com/bug.php?id=91872

for workaround when trying to connect to mysql in itself set local-infile to 1 and perform the load command: mysql --local-infile=1 -h$MASTER_DB_HOST -u$MASTER_DB_USER -p$MASTER_DB_PASSWD -D$MASTER_DB_NAME

like image 43
Nivethitha Thiyagarajan Avatar answered Oct 16 '22 17:10

Nivethitha Thiyagarajan


For ubuntu:

  1. edit the file /etc/mysql/mysql.conf.d/mysqld.cnf and add the following:
[mysqld]
secure-file-priv = ""
  1. Restart the service
systemctl restart mysql 
  1. run: mysql -u root -p and check the local infile variable

      mysql> show global variables like 'local_infile';
    
      +---------------+-------+ 
      | Variable_name | Value |
      +---------------+-------+
      | local_infile  | OFF   |
      +---------------+-------+
      1 row in set (0.00 sec)
    
  2.   mysql> set global local_infile=true;
    
      +---------------+-------+ 
      | Variable_name | Value |
      +---------------+-------+
      | local_infile  | ON    |
      +---------------+-------+
      1 row in set (0.00 sec)
    
  3.   mysql> exit
      Bye
    
  1. run

     mysql --local-infile=1 -u root -p
    
  2.   LOAD DATA INFILE '/var/lib/mysql-files/filename' INTO TABLE tablename;
    
like image 12
Utkarsh Avatar answered Oct 16 '22 17:10

Utkarsh