mysql數據庫將文件內容加載到表中報錯:
mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
LINES TERMINATED BY '\r\n';
ERROR 1148: The used command is not allowed with this MySQL version
出現這個錯誤的原因是: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命令導數據的。
解決方案:
兩個步驟:
SET GLOBAL local_infile=1;
連接數據庫時
mysql -u Name -p --local-infile=1;
使用時
conn = pymysql.connect(host="localhost",
user="root",
password="111",
db="work2forecast",
charset="utf8mb4",
local_infile=1)