Information: I am developing a PHP script for a school’s library. PHP script will be running on localhost (XAMPP), it will not be open to internet.
What I’ve tried?
CREATE TABLE IF NOT EXISTS `books` (
`Id` int(11) DEFAULT NULL,
`url` varchar(255) DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
Database’s total size is 100 GB. 100 GB is big data size for this project. In fact, 10 GB – 20 GB would be great.
a-) Is there a way to compress the text data before storing it in the mysql? I’d like to make it 20 GB
b-) I’m willing to store the datas into a file. That would be great for me if file storage made my data size 20 GB. Is there a way to accomplish it?
You can use the MySQL COMPRESS() function to compress data for storage and UNCOMPRESS() when you retrieve the result. This results in the data inserted into that column being compressed.
Alternatively, you can compress the data on the PHP side prior to inserting into MySQL. To do that, the functions
gzdeflate/gzinflateto usegzipcompression or the functionsgzcompress/gzuncompresswhich usezlibfor compression (which is the same that MySQL functions use). Using these require that PHP is built with zlib support (--with-zlib).How useful these are depends on why the database is so large. If it’s because you have hundreds of millions of records vs. fewer records with large columns then compressing certain values is unlikely to make much of a difference. You will only see a reduction in database size if you have large data. From the looks of your table structure, there is no column that requires a lot of storage.
For more information on what
ROW_FORMAT=COMPRESSEDdoes and its implications, see InnoDB Compression Usage.