mysql - 错误: Loading local data is disabled - this must be enabled on both the client and server sides

标签 mysql client local

我不明白其他人对类似问题的回答,除了最明显的问题,例如下面的问题:

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

mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile';

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | ON    |
+---------------+-------+
1 row in set (0.01 sec)

我的意思是提供了确切的代码。如果有人能够逐步引导我了解我需要做什么才能在“客户端”端和“服务器”端启用本地数据,我将不胜感激。似乎我已经在客户端启用了本地数据,但我不知道需要给我的计算机提供什么指令才能启用“服务器端”。我根本不懂技术,我只想能够将数据上传到 MySQL Workbench。

ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides
CREATE TABLE toys (
uniq_id VARCHAR(1000),
product_name VARCHAR(1000),
manufacturer VARCHAR(1000),
price VARCHAR(1000),
number_available_in_stock VARCHAR (1000),
number_of_reviews INT,
number_of_answered_questions INT,
average_review_rating VARCHAR(1000),
amazon_category_and_sub_category VARCHAR(1000),
customers_who_bought_this_item_also_bought VARCHAR(1000),
description VARCHAR(1000),
product_information VARCHAR(1000),
product_description VARCHAR(1000),
items_customers_buy_after_viewing_this_item VARCHAR(1000),
customer_questions_and_answers VARCHAR(1000),
customer_reviews VARCHAR(1000),
sellers VARCHAR(1000)
);

LOAD DATA LOCAL INFILE ‘/Users/BruddaDave/Desktop/amazonsample.csv’ INTO TABLE toys
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
IGNORE 1 LINES
(uniq_id, product_name, manufacturer, price, number_available_in_stock, number_of_reviews, number_of_answered_questions, average_review_rating, amazon_category_and_sub_category, customers_who_bought_this_item_also_bought, description, product_information, product_description, items_customers_buy_after_viewing_this_item, customer_questions_and_answers, customer_reviews, sellers)
;

我只是希望能够使用命令行 shell 将 .csv 文件导入 MySQL。

最佳答案

如果在服务器端或客户端禁用 LOCAL 功能,则尝试发出 LOAD DATA LOCAL 语句的客户端会收到以下错误消息:

ERROR 3950 (42000): Loading local data is disabled; this must be
enabled on both the client and server side

当我想按照Mysql的教程将文本文件pet.txt加载到pet表中时,遇到了同样的问题:https://dev.mysql.com/doc/refman/8.0/en/loading-tables.html

网上搜索后,我通过以下步骤修复了它:

  1. 使用以下命令设置全局变量:
mysql> SET GLOBAL local_infile=1;
Query OK, 0 rows affected (0.00 sec)
  • 退出当前服务器:
  • mysql> quit
    Bye
    
  • 使用 local-infile 系统变量连接到服务器:
  • mysql --local-infile=1 -u root -p1
    

    此变量控制 LOAD DATA 语句的服务器端 LOCAL 功能。根据 local_infile 设置,服务器拒绝或允许在客户端启用 LOCAL 的客户端加载本地数据。 要显式地使服务器拒绝或允许 LOAD DATA LOCAL 语句(无论客户端程序和库在构建时或运行时如何配置),请分别在禁用或启用 local_infile 的情况下启动 mysqld。 local_infile 也可以在运行时设置。

  • 使用您的数据库并将文件加载到表中:
  • mysql> use menagerie
    Database changed
    mysql> load data local infile '/path/pet.txt' into table pet;
    Query OK, 8 rows affected, 7 warnings (0.00 sec)
    

    有效果吗?

    引用文献:

    https://dev.mysql.com/doc/refman/8.0/en/load-data-local-security.html https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html#option_cmake_enabled_local_infile https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_local_infile

    关于mysql - 错误: Loading local data is disabled - this must be enabled on both the client and server sides,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59993844/

    相关文章:

    php - 如何在 SQL CONCAT 中转义 # 作为 URL 中的 anchor

    增加存储的数据后,mysql 性能会下降。需要有关系统诊断程序的提示

    django - 如何过滤掉 Sentry 上的错误以避免消耗我的配额?

    用于身份验证的 Apache 客户端证书

    powershell - 查找管理组名称

    mysql - 当 -SQL 时切换大小写

    java - 在 SQL 查询中使用 'true' 而不是 true 会产生意外结果

    html - 将 css 文件存储在用户系统中,直到客户端关闭我的网站

    python - 如何使用不同的数据库设置(非默认设置)启动 Django 开发服务器

    localhost - WAMP:urls 中缺少 http://localhost/,wamp 项目链接错误