开发者

How do I store a zip file in MySQL?

开发者 https://www.devze.com 2023-01-09 18:41 出处:网络
I want to write a program which will backup an entire drive in a MySQL server using java, but I am confused.

I want to write a program which will backup an entire drive in a MySQL server using java, but I am confused.

How do I create the table (what data types?), how do i insert the row like what should be the primary key, and what should be the m开发者_如何学Pythonax size of each file be?

If you have any suggestion please help me out. Thank you for sparing you time.


If the zip file is located on your MySQL host, you could use the LOAD_FILE() function to store the file in a BLOB field:

CREATE TABLE your_table (id INT, zip_file BLOB);

INSERT INTO MyTable (id, image) VALUES(1, LOAD_FILE('/tmp/your_file.zip'));

You have to make sure that the zip file is readable by MySQL, and that the MySQL user has the FILE privilege. To grant the FILE privilege, log-in as root and execute:

GRANT FILE ON *.* TO 'mysql_user'@'localhost';
0

精彩评论

暂无评论...
验证码 换一张
取 消