如何在MySQL数据库中存储.txt文件?
我可以将数据文件(例如txt文件)存储到MySql服务器吗?如果可以的话,如何保存它们?
Can I store data files (e.g. txt files) to the MySql server? If I can, how to store them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
LOAD DATA INFILE
读取文件的内容并将其以结构化格式存储在数据库的表中。这比在客户端上读取和解析文件然后使用多个 INSERT 语句要快得多。
例子:
You can use
LOAD DATA INFILE
to read the contents of a file and store it in a table in the database in a structured format.This can be considerably faster than reading and parsing the file on the client and then using multiple INSERT statements.
Example:
是的,您可以,但是您最好将它们存储在文件系统上并将文件的路径存储在数据库中。
有一些 SO 帖子讨论了这个问题:
Yes you can, but you would probably be better off storing them on the file system and storing a path to the file in the DB.
There are a few SO Posts that discuss this:
当然可以。
我建议从文件中读取数据,然后将其保存在数据库中,我会说保存在文本字段中。
您可以使用类似 this 的内容来获取文件的内容:
然后插入
Sure you can.
I would suggest reading the data from your files and then saving it in your database, i would say in a text field.
You can use something like this to get the file's content:
Then insert it
我们在这里谈论多少文字?如果没有那么多文本,您可以仅将文件的内容存储在数据库中。
您还可以将文件本身存储为 BLOB。 http://dev.mysql.com/doc/refman/5.5/en /blob.html
如果您要处理许多文件,那么最好将文件存储在服务器上,并使用数据库中的文件路径。
How much text are we talking about here? If there's not that much text, you can store just the content of the file in the database.
You can also store the file itself as a BLOB. http://dev.mysql.com/doc/refman/5.5/en/blob.html
If you'll be dealing with many files, you'll probably be better off storing the files on your sever with the file path in the database.