How should I tackle --secure-file-priv in MySQL?

前端 未结 21 1085
攒了一身酷
攒了一身酷 2020-11-22 06:04

I am learning MySQL and tried using a LOAD DATA clause. When I used it as below:

LOAD DATA INFILE \"text.txt\" INTO table mytable;
相关标签:
21条回答
  • 2020-11-22 06:26

    If you're running on Ubuntu, you may also need to configure Apparmor to allow MySQL to write to your folder, e.g. here's my configuration:

    Add this line to file /etc/apparmor.d/usr.sbin.mysqld :

    /var/lib/mysql-files/* rw
    

    Then add these 2 config lines to /etc/mysql/my.cnf sections:

    [client]
    loose-local-infile = 1
    
    [mysqld]
    secure-file-priv = ""
    

    Here's my SQL:

    select id from blahs into outfile '/var/lib/mysql-files/blahs';
    

    It worked for me. Good luck!

    0 讨论(0)
  • 2020-11-22 06:32

    On Ubuntu 14 and Mysql 5.5.53 this setting seems to be enabled by default. To disable it you need to add secure-file-priv = "" to your my.cnf file under the mysqld config group. eg:-

    [mysqld]
    secure-file-priv = ""
    
    0 讨论(0)
  • 2020-11-22 06:32

    This thread has been viewed 570k times at the time of this post. Honestly when did MySQL become our over protective unreasonable mom? What a time consuming attempt at security - which really only serves to shackle us!

    After many searches and many attempts everything failed. My solution:

    What worked for me was:

    1. Import the .csv file via PhpMyAdmin import on older box (if large do at cmd line)
    2. Generate a .sql file.
    3. Download .sql file.
    4. Import .sql file via MySQL Workbench.
    0 讨论(0)
提交回复
热议问题