LOAD_FILE returns NULL

前端 未结 4 717
忘了有多久
忘了有多久 2020-12-19 14:41

I am trying to insert an image into my MySQL server. I have done some research and it looks like the best way to do that is through LOAD_FILE(). However,

相关标签:
4条回答
  • 2020-12-19 15:10

    "FILE" is an administrative privilege. When you say that ALL privileges have been granted, does that include global administrative privileges too?

    Here's the syntax http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-global-privileges, but I found "MySQL Workbench" GUI more helpful.

    Check out OS file permissions, too.

    0 讨论(0)
  • 2020-12-19 15:17

    Using MySQL Workbench 8.0:

    1. In the Result Grid panel where you can see the rows and columns, right-click the cell that will hold the BLOB value (currently shown as NULL).
    2. In the context menu that appears, select the first item: Open Value in Editor.
    3. In the lower-left corner, there are two buttons. Click on: Load...
    4. Browse to your image file.
    5. The Binary tab is filled with the image's binary data.
    6. Click: Apply. You'll return to the Result Grid panel again. Notice NULL has been replaced by BLOB.
    7. Right-click BLOB and select Open Value in Editor once more.
    8. You'll find a new tab at the top: Image. There you can preview the image you just added.

    Greetings!

    0 讨论(0)
  • 2020-12-19 15:18

    Here is my command on windows 7:

    select load_file("C:/Program Files (x86)/MySQL/MySQL Workbench CE 6.0.7/images/hieuImages/a.jpg");
    

    And it worked! You maybe try to copy your images into that directory and select again in mysql.

    0 讨论(0)
  • 2020-12-19 15:18

    I had the same issue.

    Fond out that the file to be loaded, needs to be in the folder location where mysql/mariadb has privileges to read it. It can be configured, BUT the data folder is already has access right.

    In my case I copied my file to data folder: C:\Program Files\MariaDB 10.3\data And than I just called it with full path:

    select load_file('C:\\Program Files\\MariaDB 10.3\\data\\test.txt');
    
    0 讨论(0)
提交回复
热议问题