0

I want to know that sql database contains data in the form of table Using plain text. Can we save or upload any images,videos or othet files to mysql If there is any way then how it will be done???

Junaid
  • 1
  • 1
    Does this answer your question? [How to insert a file in MySQL database?](https://stackoverflow.com/questions/5959043/how-to-insert-a-file-in-mysql-database) – Martheen May 23 '20 at 05:34
  • 1
    Note that unless the files are small, or very rarely accessed again, storing the file in the filesystem and record their path in DB is usually a far better idea – Martheen May 23 '20 at 05:37

1 Answers1

2

Yes, MySQL can store any object even though that's probably a bad idea.

BLOB and TEXTcolumn types and their LONGBLOB and LONGTEXT counterparts can be used to store large objects as well. For example

CREATE TABLE filestorage (
 id INT PRIMARY KEY AUTO_INCREMENT,
 content BLOB
);

See documentation for more information.

That said, usually storing videos and large binary objects in MySQL is a bad idea. Without knowing the full details of your scenario it might be better idea to just store the files as regular files and reference them in the database. e.g.

CREATE TABLE filereferences (
  id INT PRIMARY KEY AUTO_INCREMENT,
  filename VARCHAR(128),
  storagepath VARCHAR(255) UNIQUE
);

File names can be sturctured so thaat they limit number of files per directory to avoid excessive seek times and to distribute them across various filesystems. e.g.:

File uploaded as "flower.png" could be stored as 2b00042f7481c7b056c4b410d28f33cf.png and full path might be /media/2b/00/04/2f/2b00042f7481c7b056c4b410d28f33cf.png

vhu
  • 12,244
  • 11
  • 38
  • 48