[MariaDB:Load-Local-Infile] The used command is not allowed with this MariaDB version

[MariaDB:Load-Local-Infile] The used command is not allowed with this MariaDB version

问题描述

使用jdbc执行load data local infile ‘sql.csv’ into table test fields terminated by ‘,’;时报错:

The used command is not allowed with this MariaDB version.

环境参数

mariadb:10.4.10
mysql-connector-java:8.0.20

官方文档说明及解决办法

查看了官方文档关于load-data-local-infile的说明:

The LOAD DATA LOCAL INFILE statement can be disabled on the server by 
setting the local_infile system variable to 0.

因此,首先需检查mariadb中的local_file参数的值。在数据库中执行语句:

show global variables like%local%;

结果如下:

MariaDB [mysql]> show global variables like '%local%';'
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | ON    |
+---------------+-------+
1 row in set (0.001 sec)

处于开启的状态,但为什么执行报错?
查看文档的后续说明:

If the LOAD DATA LOCAL INFILE statement is disabled by 
either the server or the client and if the user attempts to execute it, 
then the server will cause the statement to fail with the following 
error message:
The used command is not allowed with this MariaDB version.
Note that it is not entirely accurate to say that the MariaDB version 
does not support the command. It would be more accurate to say that 
the MariaDB configuration does not support the command. 
See MDEV-20500 for more information.
From MariaDB 10.5.2, the error message is more accurate:
The used command is not allowed because the MariaDB server or client 
  has disabled the local infile capability

说明不仅需在服务端将local_infile参数设置为开启,在客户端也应设置相应的参数。
关于mysql-connector-java的连接参数设置,参见:jdbc-mysql连接参数配置
其中,关于local_infile的设置,参见:
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-connp-props-security.html
中的allowLoadLocalInfile一项,即,需在url中添加allowLoadLocalInfile=true。
示例:

jdbc:mysql://127.0.0.1:3306/test?
useUnicode=true&characterEncoding=utf8&allowLoadLocalInfile=true
以下是在Ubuntu系统上安装MySQL 8.0.32后的默认 /etc/mysql/my.cnf 文件内容: ``` # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql #skip-external-locking skip-name-resolve skip-host-cache skip-ssl sql-mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION log-error = /var/log/mysql/error.log # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Recommended in standard MySQL setup # sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # # * Character sets # # MySQL/MariaDB default is Latin1, but in Ubuntu UTF-8 is default # character-set-server = utf8mb4 collation-server = utf8mb4_general_ci # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates you can use for example the GUI tool "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysql] # # * Basic Settings # socket = /var/run/mysqld/mysqld.sock prompt = \u@\h [\d]>\_ [mysqldump] # # * Basic Settings # socket = /var/run/mysqld/mysqld.sock quick quote-names max_allowed_packet = 16M [isamchk] key_buffer = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ ``` 注意,这只是默认的配置文件,实际上你可以根据需要进行修改。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值