我正在尝试使用“MySQL 维度数据仓库”一书来理解数据仓库。在第 2 章中,我需要将数据插入到 MySQL 中的表中。
我正在尝试这段代码
TRUNCATE customer_stg;
LOAD DATA INFILE 'customer2.csv'
INTO TABLE customer_stg
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES(
customer_number,
customer_name,
customer_street_address,
customer_zip_code,
customer_city,
customer_state
);
我在 Ubuntu 12.04.2 上使用 lampp。文件“customer2.csv”已复制到文件夹“/opt/lampp/var/mysql/dw”。 在 MySQL 中,我使用用户“dwid”,密码为“password”。 csv文件的文件权限设置为
-rwxr-xr-x 1 mysql mysql 469 Oct 31 2005 customer2.csv
但我仍然无法加载表中的数据。可以从用户“root”进行加载。
最佳答案
来自 MySQL 5.5 手册页:
LOCAL works only if your server and your client both have been configured to permit it. For example, if mysqld was started with --local-infile=0, LOCAL does not work. See Section 6.1.6, “Security Issues with LOAD DATA LOCAL”.
您应该设置选项:
local-infile=1
进入 my.cnf 文件的 [mysql] 条目或使用 --local-infile 选项调用 mysql 客户端:
mysql --local-infile -uroot -pyourpwd yourdbname
您必须确保在 [mysqld] 部分中也定义了相同的参数,才能启用服务器端的“本地 infile”功能。
这是一个安全限制。我从 stackoverflow 中的其他问题中了解到这一点,我找不到链接,我保存了答案。希望这会有所帮助。
关于mysql - 使用 CSV 将数据导入 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23301668/