MYSQL-执行“load data local infile”报错“The used command is not allowed with this MySQL version”

来源:互联网 发布:公务员工资计算软件 编辑:程序博客网 时间:2024/05/21 19:55

MYSQL在执行“load data local infile”的时候报错“The used command is not allowed with this MySQL version”,本人所用的版本是 “5.5.38-0+wheezy1”,然后在网上找到了下面这篇文章,得到的解决方案。


在部署在不同机器上的mysql数据库之间导数据时,load data infile是一个很高效的命令,从host1的db1.table1通过select ... into outfile将数据导入文本文件,然后通过load data infile将数据导入host2的db2.table1。

       使用过程中碰到一些典型问题及并最终找到解决方法。作为笔记,记录与此。

1. root用户(这里只mysql的root,非Linux系统的root)在mysql server部署机器通过load data infile命令导入数据时,只要文件路径指定正确,一般不会有问题

2. 非root用户在mysql server部署机器通过load data infile命令导入数据时,报错:
       ERROR 1045 (28000): Access denied for user 'xxx'@'xxx' (using password: YES)
       可能原因:这个一般是因为非root用户没有FILE Privilege,可以通过show grants查看当前登陆用户的权限,也可以通过select mysql.user查看某用户的权限,一般情况下,normal user是无FILE权限的
       三种解决办法:
       1)命令加local参数,用load data local infile 'filename' into table xxx.xxx来导数据(推荐使用)
       2)给normal user开通FILE Privilege,注意:FILE权限与SELECE/DELETE/UPDATE等不同,后者是可以具体指定到某个db的某个表的,而FILE则是全局的,即只能通过grant FILE on *.* to 'xxx'@'xxx'才能使FILE权限对所有db的所有tables生效。通过grant all on db.* to 'xxx'@'xxx'不能使指定的user在指定的db上具有FILE权限。
       根据最小权限原则(操作系统安全的概念),这个方法并不安全,故不推荐使用。
       3)修改.my.cnf中的配置,具体方法见此处

3. 非root用户从client机器load data local infile至remote mysql server时,报错:
       ERROR 1148 (42000): The used command is not allowed with this MySQL version
       可能原因(from mysql reference manual):
       If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts to issue such a statement receives the following error message:
       ERROR 1148: The used command is not allowed with this MySQL version
       可见,出于安全考虑,默认是不允许从client host远程通过load data命令导数据的
       解决办法:
       For the mysql command-line client, enable LOAD DATA LOCAL by specifying the --local-infile[=1]option, or disable it with the --local-infile=0 option
       也即,在需要从client host导数据的情况下,登陆mysql时,需用--local-infile[=1]显式指定参数,典型命令形式为:
        mysql --local-infile -u user -ppasswd
       登陆成功后,执行load data infile 'filename' into table xxx.xxx即可


原文:http://blog.csdn.net/slvher/article/details/8768468

0 0