html - 如何使用 MySQL Workbench 将文件存储在 MySQL 数据库中?

标签 html mysql database mysql-workbench

我正在尝试将 .html 文件存储在 MySQL 数据库中(使用 MySQL Workbench)。目前我正在尝试执行 load_file('filepath') ,以便可以读取 .html 文件的内容并将其转换为字符串,并且该字符串将存储在数据库的表中。但问题是它似乎总是返回 null,所以我无法检查它是否真的在工作。

我知道 load_file 需要满足 4 个条件才能正常工作,但我不知道必须执行哪些脚本才能授予权限。由于我试图将文件的内容转换为字符串,也许还有另一种更有效的方法将整个 .html 文件存储到数据库中,如果是的话,有人可以告诉我如何做到这一点吗?我的 MySQL 服务器的用户名是 root,并且在 Mac 操作系统上运行。

最佳答案

load_file function说:

To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the FILE privilege. The file must be readable by all and its size less than max_allowed_packet bytes. If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.

因此,有许多条件可以检查您是否确实可以加载文件。首先检查您的用户是否具有 FILE 权限以及您的 MySQL 服务器是否可以访问该文件。

关于html - 如何使用 MySQL Workbench 将文件存储在 MySQL 数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45856068/

相关文章:

html - 将 html 链接到 css 在 Google Chrome 上不起作用

Html 和 Css 文件没有链接

mysql - AWS RDS (MySQL) 安全连接

sql - 从sql中提取字符详细信息的特定位置

javascript - 如何链接两个html页面

css - 如何在 html 中为 <p> 标签设置背景颜色;这样背景颜色就不会超过文字?

mysql - rails : can't migrate database

php - 我如何将 csv 文件中的 utf-8 设置为 phpmyadmin

mysql - 仅当新值大于列中的现有值时,如何更新行?

mysql - 所有用户在 phpMyAdmin 中都没有权限