mysql在windows上加载数据本地填充不工作

64jmpszr  于 2021-06-20  发布在  Mysql
关注(0)|答案(5)|浏览(409)

我使用的是安装了mysql 8.0的windows。
我已经检查了stackoverflow上已经发布的解决方案,但是没有立即的结果。
我已经用 SET GLOBAL local_infile = 1; 此选项现在似乎已启用,但mysql不断抛出以下错误:
错误代码:
此mysql版本不允许使用used命令
有人能帮我纠正这种行为吗?

bmp9r5qi

bmp9r5qi1#

windows10用户:确认windows使用哪个帐户来运行mysql服务是多么重要,这一点值得重复。
这个问题在Windows10的MySQL8.0.21中仍然存在。与 LOAD DATA INFILE (而不是 LOAD DATA INFILE LOCAL ,即使在同一桌面上运行客户端和服务器,也需要额外的文件传输)我开始收到以下错误: not found (OS errno 13 - Permission denied) 出于某种原因,mysql决定选择“networkservices”,可能是因为我将安装从默认的c:驱动器移到了d:
不:

最初的安装设置了local,我选择了“local system account”单选按钮,这就为我解决了这个问题。
对:

mysql文档鼓励将mysql作为windows服务在windows上运行,但是对于指定哪个帐户作为服务的登录没有给出建议。
和其他许多人一样,我浏览了所有选项(local\u infle等),但直到看到来自cesaring的答案才检查服务登录,我现在欠他一杯啤酒或咖啡。

flseospp

flseospp2#

我有同样的问题后,搜索,我解决了从查询中删除本地关键字的问题。

SET GLOBAL local_infile = 1;
SHOW VARIABLES LIKE 'local_infile';

查询应返回:on
查询应如下所示:

load data infile 'C:\\CA_DRU_proj_2010-2060.csv'
into table pop_proj
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;

你应该注意到,我删除了本地关键字从这里,现在它的工作正常。

z9gpfhce

z9gpfhce3#

截至2019年1月,这是mysql workbench 8.0.12的一个未解决的错误。请参见:https://bugs.mysql.com/bug.php?id=91891 .
但是,如果“local\u infle”全局变量已设置为1,则通过cli执行相同的命令应该可以工作:
设置@@global.local\u infle=1;

rdrgkggo

rdrgkggo4#

我一直在处理一个类似的问题,在windows上使用mysql 8.0.19。我没有使用local关键字,而是使用windows服务管理器(在资源管理器任务栏上键入services),右键单击mysql80->选择properties,然后在logon选项卡上,将logon as:value更改为local system account。

8qgya5xd

8qgya5xd5#

尝试:
文件: Z:\Path\To\MySQL\Files\my_file.csv :

1,"a string"
2,"a string containing a , comma"
3,"a string containing a \" quote"
4,"a string containing a \", quote and comma"

mysql命令行:

Z:\>mysql
Enter password:**************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> DROP TABLE IF EXISTS `_`.`my_table`;
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> CREATE TABLE IF NOT EXISTS `_`.`my_table` (
    ->   `col0` INT NOT NULL PRIMARY KEY,
    ->   `col1` VARCHAR(50) NOT NULL
    -> );
Query OK, 0 rows affected (0.45 sec)

mysql> SHOW VARIABLES WHERE `variable_name` = 'secure_file_priv';
+------------------+-------------------------+
| Variable_name    | Value                   |
+------------------+-------------------------+
| secure_file_priv | Z:\Path\To\MySQL\Files\ |
+------------------+-------------------------+
1 row in set (0.00 sec)

mysql> LOAD DATA LOCAL INFILE 'Z:\\Path\\To\\MySQL\\Files\\my_file.csv'
    ->   INTO TABLE `_`.`my_table`
    ->   FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    ->   LINES TERMINATED BY '\r\n';
ERROR 1148 (42000): The used command is not allowed with this MySQL version

mysql> SELECT @@GLOBAL.`local_infile`;
+-------------------------+
| @@GLOBAL.`local_infile` |
+-------------------------+
|                       0 |
+-------------------------+
1 row in set (0.00 sec)

mysql> SET @@GLOBAL.`local_infile` := 1;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @@GLOBAL.`local_infile`;
+-------------------------+
| @@GLOBAL.`local_infile` |
+-------------------------+
|                       1 |
+-------------------------+
1 row in set (0.00 sec)

mysql> LOAD DATA LOCAL INFILE 'Z:\\Path\\To\\MySQL\\Files\\my_file.csv'
    ->   INTO TABLE `_`.`my_table`
    ->   FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    ->   LINES TERMINATED BY '\r\n';
ERROR 1148 (42000): The used command is not allowed with this MySQL version

mysql> SELECT `col0`, `col1`
    -> FROM `_`.`my_table`;
Empty set (0.00 sec)

mysql> exit
Bye

Z:\>mysql --local-infile=1
Enter password:**************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> SELECT @@GLOBAL.`local_infile`;
+-------------------------+
| @@GLOBAL.`local_infile` |
+-------------------------+
|                       1 |
+-------------------------+
1 row in set (0.00 sec)

mysql> LOAD DATA LOCAL INFILE 'Z:\\Path\\To\\MySQL\\Files\\my_file.csv'
    ->   INTO TABLE `_`.`my_table`
    ->   FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    ->   LINES TERMINATED BY '\r\n';
Query OK, 4 rows affected (0.19 sec)
Records: 4  Deleted: 0  Skipped: 0  Warnings: 0

mysql> SELECT `col0`, `col1`
    -> FROM `_`.`my_table`;
+------+------------------------------------------+
| col0 | col1                                     |
+------+------------------------------------------+
|    1 | a string                                 |
|    2 | a string containing a , comma            |
|    3 | a string containing a " quote            |
|    4 | a string containing a ", quote and comma |
+------+------------------------------------------+
4 rows in set (0.00 sec)

相关问题