mysqlmacosmysql-loadfile

LOAD_FILE returns only null


I want to insert the image to the database with this query:

SELECT LOAD_FILE('/Users/juliagaskevich/cool-background.svg');

I checked that:

System configuration:

macOS Monterey, version 12.5, chip Apple M1

MySQL Ver 8.0.29 for macos12 on arm64 (MySQL Community Server - GPL) MySQL Config:

[mysqld]
user = mysql_deamon
slow_query_log_file = my-slow-query.log
slow-query-log
log-queries-not-using-indexes
general_log_file = my-GENERAL.log
max_allowed_packet = 1073741824

Also, I tried to fix my problem with guys' ideas, but...


1.vi my.cnf

secure-file-priv=/mysql/dataload(Change /mysql/dataload to your own directory.)

2.restart mysql service

Changed my.cnf

Changed my.cnf (without quotes in secure-file-priv path)


The statement SELECT LOAD_FILE(...) delivers one string. To INSERT, use the statement LOAD DATA INFILE ...

1290 ERROR with null secure_file_priv result


Solution

  • SOLVING

    If you are using mac, you have the /etc/my.cnf (file, where is MySQL config stored), so put there this string secure_file_priv = ""

    Run this to apply config changes mysqld --defaults-file=/etc/my.cnf --validate-config --log_error_verbosity=2 AND IF you have any warnings or errors fix it, because it can solve your problem

    If you are using some different user than root, the user have to have a FILE privileges mysql> GRANT privilege ON privilege_level TO account_name;, for example mysql> GRANT FILE ON *.* TO pizzaadmin;


    The most important thing: To apply changes, you have to restart mysqld.

    There are few steps:

    1. stop it (You can do this with this command mysqladmin shutdown)
    2. start again (You can do this with just executing mysqld in terminal)