我想将.csv文件上传到MySQL Docker。
收到错误:File 'xx.csv' not found (OS errno 13 - Permission denied)
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD password
COPY ./sql-scripts/ /docker-entrypoint-initdb.d/
COPY ./data /var/lib/mysql/
COPY my.cnf /etc/mysql/
EXPOSE 3306
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv = ""
local-infile = 1
symbolic-links=0
!includedir /etc/mysql/conf.d/
docker exec -it mysql_1 mysql -uroot -proot_password
CREATE DATABASE data;
USE data;
CREATE TABLE IF NOT EXISTS `pregnant_mapping` (
`label` varchar(255),
`Pregnancy` varchar(255) PRIMARY KEY
);
LOAD DATA INFILE '/var/lib/mysql/pregnant_mapping.csv' INTO TABLE pregnant_mapping;
试图在命令行中添加LOCAL
,但是在我的MySQL版本中不起作用;得到了错误:ERROR 1148 (42000): The used command is not allowed with this MySQL version
感谢您的帮助!
答案 0 :(得分:0)
如果将.csv文件放在/ var / lib / mysql目录中,则下面的语句应该起作用
LOAD DATA INFILE'/ var / lib / mysql / result'到表mst_result字段中,以','可选,并以'“'结尾,并以'\ n'终止;
答案 1 :(得分:0)
看到这个问题有点晚,但也许答案可能对某人有所帮助:
平台:Linux (CENTOS 8)
[mysqld]
local-infile = 1
服务mysqld重启
mysqlimport --user=${user} --password=${password} --local=TRUE -d ${database} your_file
在需要时向 mysqlimport 添加其他参数。