22

有谁知道为什么在运行 mysqlimport 时出现此错误?

mysqlimport -u someone -pwhatever --columns=a,b,c,d,e bar /var/tmp/baz.sql
mysqlimport: Error: 1045, Access denied for user 'someone'@'%' (using password: YES), when using table: baz

然而...

mysql -u someone -pwhatever
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 199
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants;
+------------------------------------------------------------------------------------------------------------+
| Grants for someone@%                                                                                   |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'someone'@'%' IDENTIFIED BY PASSWORD '*BLAHBLAHBLAH' |
| GRANT ALL PRIVILEGES ON `bar`.* TO 'someone'@'%'                                          |
+------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>
4

4 回答 4

32

您可以通过对 mysqlimport 使用 --local 参数来避免对额外权限的需要:

--local, -L

           Read input files locally from the client host.
于 2012-02-26T13:03:54.130 回答
25

好的,事实证明 FILE 权限是一个“全局”权限,这显然意味着您不能在某些数据库、表上选择性地启用它。等等。这就是为什么我之前关于 bar.* 的授权声明没有效果:

GRANT ALL PRIVILEGES ON `bar`.* TO 'someone'@'%' 

您需要授予 FILE 权限*.*

GRANT FILE ON *.* to 'someone'@'%';

希望这可以帮助某人。

于 2011-07-26T22:45:29.703 回答
13

有些人会选择此命令,跳过额外的 FILE 授权。

mysql -u username -p <yourdbname> < yourfile.sql

于 2013-10-15T19:06:01.877 回答
6

mysqlimport 是 LOAD DATA INFILE 语句的命令行界面,您需要 'FILE' 权限(服务器级别)。

LOAD DATA INFILE 语法

Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege.
于 2011-07-26T22:13:51.683 回答