錯誤:載入本機資料已停用 - 必須在用戶端和伺服器端啟用此功能
P粉116631591
P粉116631591 2023-08-29 12:12:03
0
1
373
<p>我不明白其他人對類似問題的回答,除了最明顯的問題,例如下面的問題:</p> <pre class="brush:php;toolbar:false;">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)</pre> <p>我的意思是提供了確切的程式碼。如果有人能夠逐步引導我了解我需要做什麼才能在「客戶端」端和「伺服器」端啟用本地數據,我將不勝感激。似乎我已經在客戶端啟用了​​本地數據,但我不知道需要給我的電腦什麼指令才能啟用「伺服器端」。我根本不懂技術,我只想能夠將資料上傳到 MySQL Workbench。 </p> <pre class="brush:php;toolbar:false;">ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides</pre> <pre class="brush:php;toolbar:false;">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, 非items_customers_buy_after_viewing_this_item, customer_questions_and_answers, customer_reviews, sellers) ;</pre> <p>我只是希望能夠使用命令列 shell 將 .csv 檔案匯入 MySQL。 </p>
P粉116631591
P粉116631591

全部回覆(1)
P粉316890884

如果在伺服器端或用戶端停用 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)
  1. 退出目前伺服器:
mysql> quit
Bye
  1. 使用 local-infile 系統變數連接到伺服器:
mysql --local-infile=1 -u root -p1

此變數控制 LOAD DATA 語句的伺服器端 LOCAL 功能。根據 local_infile 設定,伺服器拒絕或允許在客戶端啟用 LOCAL 的客戶端載入本機資料。 若要明確地使伺服器拒絕或允許 LOAD DATA LOCAL 語句(無論用戶端程式和程式庫在建置時或執行時如何配置),請分別在停用或啟用 local_infile 的情況下啟動 mysqld。 local_infile 也可以在執行時設定。

  1. 使用您的資料庫並將檔案載入到表中:
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

#
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!