如何在MacOS上将CSV文件上传到Mysql? [英] How do I upload a CSV file into Mysql on MacOS?

查看:44
本文介绍了如何在MacOS上将CSV文件上传到Mysql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码行:

  LOAD DATA LOCAL INFILE'CA_DRU_proj_2010-2060.csv'插入表pop_proj以','终止的字段封闭在'"'以'\ n'结尾的行忽略1行; 

我收到的错误是:

错误代码:1148.此MySQL版本不允许使用命令

我的mysql版本是8.0.16版本

解决方案

您需要服务器和客户端才能启用本地文件导入.

服务器需要启用 local_infile = 1 .您可以将其放在 my.cnf 选项文件中,也可以使用 SET GLOBAL local_infile = 1;

在正在运行的服务器上动态启用它

您还需要告诉客户允许它.通过启动客户端来做到这一点:

  mysql --local-infile = 1 ... 

自MySQL 8.0.19起,错误消息更加清晰:

错误3950(42000):禁止加载本地数据;这一定是在客户端和服务器端均已启用

另请参阅:

  • I am using the following lines of code:

    LOAD DATA LOCAL INFILE 'CA_DRU_proj_2010-2060.csv'
    INTO TABLE pop_proj
    FIELDS TERMINATED BY ' , '
    ENCLOSED BY ' " '
    LINES TERMINATED BY ' \n '
    IGNORE 1 LINES;
    

    The error I am receiving is:

    Error Code: 1148. The used command is not allowed with this MySQL version

    My version of mysql is version 8.0.16

    解决方案

    You need both the server and the client to enable local-infile import.

    The server needs to enable local_infile=1. You can put this in your my.cnf options file, or you can enable it dynamically on a running server with SET GLOBAL local_infile=1;

    You also need to tell the client to allow it. Do this by starting the client:

    mysql --local-infile=1 ...
    

    Since MySQL 8.0.19, the error message is more clear:

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

    See also:


    Update: If you use MySQL Workbench instead of the mysql command line client, you can enable local-infile in the options on the Advanced tab of your connection profile. See highlighted line below:

    这篇关于如何在MacOS上将CSV文件上传到Mysql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆